SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 13/01/2015, 04:49 PM   #1
ikkentim
High-roller
 
ikkentim's Avatar
 
Join Date: Jan 2010
Location: Kampen, The Netherlands
Posts: 1,052
Reputation: 205
Default async/threaded calls to natives

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.
__________________
Greetings,
Tim Potze

Projects
GAMEDEV | Part-time developer working on Parkitect. | Steampage
LSRES | A SA:MP server from the past, and hopefully, back in the future.
SampSharp | Plugin for writing SA:MP gamemodes in C#. | Topic Website Github
SanMap | San Andreas in G00GLE MAPS! | Topic Github Sample
ikkentim is offline   Reply With Quote
Old 13/01/2015, 05:21 PM   #2
nGen.SoNNy
Gangsta
 
nGen.SoNNy's Avatar
 
Join Date: Sep 2009
Location: Romania
Posts: 929
Reputation: 69
Default Re: async/threaded calls to natives

Wrong section dude
__________________
If i've helped you, please click
nGen.SoNNy is offline   Reply With Quote
Old 13/01/2015, 05:30 PM   #3
maddinat0r
Banned
 
Join Date: Jun 2010
Location: Germany
Posts: 845
Reputation: 482
Default Re: async/threaded calls to natives

Quote:
Originally Posted by nGen.SoNNy View Post
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.
maddinat0r is offline   Reply With Quote
Old 13/01/2015, 05:42 PM   #4
ikkentim
High-roller
 
ikkentim's Avatar
 
Join Date: Jan 2010
Location: Kampen, The Netherlands
Posts: 1,052
Reputation: 205
Default Re: async/threaded calls to natives

Quote:
Originally Posted by maddinat0r View Post
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
__________________
Greetings,
Tim Potze

Projects
GAMEDEV | Part-time developer working on Parkitect. | Steampage
LSRES | A SA:MP server from the past, and hopefully, back in the future.
SampSharp | Plugin for writing SA:MP gamemodes in C#. | Topic Website Github
SanMap | San Andreas in G00GLE MAPS! | Topic Github Sample
ikkentim is offline   Reply With Quote
Old 13/01/2015, 06:24 PM   #5
maddinat0r
Banned
 
Join Date: Jun 2010
Location: Germany
Posts: 845
Reputation: 482
Default Re: async/threaded calls to natives

I'd add a mutex to be 100%ly sure, but IMHO (and by experience) logprintf is working fine when called from multiple threads.
maddinat0r is offline   Reply With Quote
Old 13/01/2015, 09:11 PM   #6
ikkentim
High-roller
 
ikkentim's Avatar
 
Join Date: Jan 2010
Location: Kampen, The Netherlands
Posts: 1,052
Reputation: 205
Default Re: async/threaded calls to natives

Thanks you all for the info!
__________________
Greetings,
Tim Potze

Projects
GAMEDEV | Part-time developer working on Parkitect. | Steampage
LSRES | A SA:MP server from the past, and hopefully, back in the future.
SampSharp | Plugin for writing SA:MP gamemodes in C#. | Topic Website Github
SanMap | San Andreas in G00GLE MAPS! | Topic Github Sample
ikkentim is offline   Reply With Quote
Old 14/01/2015, 04:15 AM   #7
][Noname][
Gangsta
 
][Noname]['s Avatar
 
Join Date: Dec 2010
Posts: 637
Reputation: 92
Default Re: async/threaded calls to natives

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
][Noname][ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone explain simply the difference between Threaded and Non-Threaded Querys Dokins Scripting Help 3 14/04/2014 10:59 AM
Threaded and non threaded queries CoDeZ Scripting Help 3 12/09/2012 01:17 PM
[FilterScript] Profiles [email, phone, FRIEND LISTS, calls + group calls, etc..] Sinner Filterscripts 16 03/07/2012 10:05 PM
Natives GaGlets(R) Help Archive 0 01/08/2010 02:45 AM
911 calls Steven82 Help Archive 9 19/03/2010 07:44 AM


All times are GMT. The time now is 08:27 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.