async/threaded calls to natives - 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: Plugin Development (
https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: async/threaded calls to natives (
/showthread.php?tid=557333)
async/threaded calls to natives -
ikkentim - 13.01.2015
Hi,
I'm working on my plugin, SampSharp and I was working some threading related stuff. In this threaded function I use calls to sampgdk_logprintf. This seems to work fine. I also tried calling the SendClientMessage native. This seems to work fine as well.
My question is: Is calling natives from different threads bad and could calling natives from different threads cause issues/crashes?
my only guess would by that pawn's stack might corrupt at simultaneous calls but I'm not even sure that the machine touches the stack when calling natives trough sampgdk.
Re: async/threaded calls to natives -
nGen.SoNNy - 13.01.2015
Wrong section dude
Re: async/threaded calls to natives -
maddinat0r - 13.01.2015
Quote:
Originally Posted by nGen.SoNNy
Wrong section dude
|
Yeah, no, not really.
@OP:
Yes, calling natives outside the PAWN thread is bad and will lead you sooner or later to a crash. Even if none of the AMX-stuff would be touched, there are still the underlying network functions and you can't know if they are implemented thread-safe or not.
Re: async/threaded calls to natives -
ikkentim - 13.01.2015
Quote:
Originally Posted by maddinat0r
Yeah, no, not really.
@OP:
Yes, calling natives outside the PAWN thread is bad and will lead you sooner or later to a crash. Even if none of the AMX-stuff would be touched, there are still the underlying network functions and you can't know if they are implemented thread-safe or not.
|
Hmm.. I guess you are right. Would you think printing to the log (trough sampgdk, sampgdk_logprintf) alone would be safe to use? It's quite a fundamental function
Re: async/threaded calls to natives -
maddinat0r - 13.01.2015
I'd add a mutex to be 100%ly sure, but IMHO (and by experience) logprintf is working fine when called from multiple threads.
Re: async/threaded calls to natives -
ikkentim - 13.01.2015
Thanks you all for the info!
Re: async/threaded calls to natives -
][Noname][ - 14.01.2015
logprintf (printf in pawn) are multithread safe, but whats happen?
logprintf("111") in 1'st thread
logprintf("222") in 2'nd
you can find - 112122