View previous topic :: View next topic |
Author |
Message |
gedrin
Joined: 14 Mar 2011 Posts: 2
|
Posted: Mon Mar 14, 2011 18:20 Post subject: Single Threaded? |
|
|
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 |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Mon Mar 14, 2011 19:06 Post subject: |
|
|
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 |
|
|
gedrin
Joined: 14 Mar 2011 Posts: 2
|
Posted: Mon Mar 14, 2011 19:19 Post subject: |
|
|
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 |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Mon Mar 14, 2011 19:24 Post subject: |
|
|
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 |
|
|
|