logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Single Threaded?

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
gedrin



Joined: 14 Mar 2011
Posts: 2

PostPosted: Mon Mar 14, 2011 18:20    Post subject: Single Threaded? Reply with quote

Sorry if this has been asked before but I wanted to confirm this before I descend down a rathole.

I am rather new to scripting and this looked like a good place to ask some questions.

My question is this.
Are all the scripts executed by a single thread or is it a single thread per event.

If for example I have on one event... say the module heartbeat a call to the function
DoSomething()

and on another event... say the OnClick event of a transition, I also call
DoSomething()

is it at all possible that DoSomething() may have 2 threads running in it at the same time?

Thanks for your time
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Mar 14, 2011 19:06    Post subject: Reply with quote

It depends on whether DoSomething involves calls to NWServer internals. NWServer is signgle-threaded, and attempts to mess with it from another thread will eventually result in a crash.
If DoSomething is doing something completely different (filesystem or DB calls, for example), it's safe to do that in a separate thread.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
gedrin



Joined: 14 Mar 2011
Posts: 2

PostPosted: Mon Mar 14, 2011 19:19    Post subject: Reply with quote

DoSomething() actually just does some GetLocalInt/String/ArrayInt/ArrayString on a few objects.... makes some calculations... then writes with some SetLocalInt/String/ArrayInt/ArrayString on a few objects.


I am not sure if this is what you mean by NWServer internals.

I did not want to create seperate threads to do tasks.... honstly I dont know how to do that explicitly [Your comment makes me think there is a way... and since I dont want that at all I would like to know how to ensure I do not do things on a seperate thread]

My central question is just whether Event Handlers are executed concurrently by multiple threads or if it is the same thread that exec's scripted event handlers in sequence.

Or in other words... do I ever need to put Mutex around critical sections in nwn2 scripting?
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Mar 14, 2011 19:24    Post subject: Reply with quote

No, it's all single-threaded: there is only one script running at any given time.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group