async/threaded calls to natives
#1

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.
Reply
#2

Wrong section dude
Reply
#3

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.
Reply
#4

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
Reply
#5

I'd add a mutex to be 100%ly sure, but IMHO (and by experience) logprintf is working fine when called from multiple threads.
Reply
#6

Thanks you all for the info!
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)