MySQL related; server gets stuck - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL related; server gets stuck (
/showthread.php?tid=359515)
MySQL related; server gets stuck -
Jochemd - 14.07.2012
Hello,
pawn Код:
stock GetFreeDiskID()
{
GlobalInfo[LoadingDatabaseFinished] = 0;
mysql_function_query(1,"SELECT * FROM `CompactDiskInfo`",true,"ReturnFreeDatabaseID","","");
for(;;) if(GlobalInfo[LoadingDatabaseFinished] == 1) break; // Breaking first to avoid the 'return a value' warning
return GlobalInfo[ReturnDatabaseID];
}
pawn Код:
public ReturnFreeDatabaseID()
{
new fields;
cache_get_data(GlobalInfo[ReturnDatabaseID],fields);
GlobalInfo[LoadingDatabaseFinished] = 1;
return 1;
}
How come the server gets stuck? It's obvious it has to do with the loop, but the MySQL function runs as it's threaded and should be done very soon.
Jochem
Re: MySQL related; server gets stuck -
pyrodave - 14.07.2012
The plugin may be multithreaded but pawn is not. The plugin cannot pass a value to the callback because its executing your loop and execution won't be handed back until it finishes (which of course, it wont). What you're trying to do cannot be done with the multithreading enabled. (Simply returning a value in a function like that).
The best solution off the top of my head would be to store a static or global variable for your FreeDiskID and update it as disks are used and freed. There are probably better solutions however its difficult to say without knowing the nature of the full system.
Re: MySQL related; server gets stuck -
Jochemd - 14.07.2012
Quote:
Originally Posted by pyrodave
The best solution off the top of my head would be to store a static or global variable for your FreeDiskID and update it as disks are used and freed. There are probably better solutions however its difficult to say without knowing the nature of the full system.
|
I did not fully get you there; Do you mind making a small example?
Re: MySQL related; server gets stuck -
AndreT - 14.07.2012
GetFreeDiskID and ReturnFreeDatabaseID do not run in separate threads. That's why ReturnFreeDatabaseID can never run (the server is stuck in a loop in GetFreeDiskID). This is not how you are supposed to thread stuff.