In your documentation in the "Thing to think about in multithreading" you state:
- Multiple threads may execute scripts in separate contexts. The contexts may execute scripts from the same module, but if the module has global variables you need to make sure the scripts perform proper access control so that they do not get corrupted, if multiple threads try to update them simultaneously.
So with that said in the scenario where i have 1 engine created. with 2 threads alive. Now each thread is designated its own personal context-pool. Now note: Each allocate script-class instance assigned to a specific thread and will always run on that thread. aka a script instances executing in thread 0 can not access/talk/write with another script instances executing in thread 1.
Now the issue comes with this asCThreadLocalData when a context execute a function. When the context executes a function it will access the threadlocaldata and attempt to push the active stack on to the thread shared memory (memory of the thread that allocated the engine, which there is one). Then it follows with a pop when unprepare is called.
As you can see this pushing/popping on the thread local data is not safe ( which makes sense since its called thread-local data, 1-per engine). But that would mean that you cant ever invoke two script classes member functions using 2 different context from 2 different thread simultaneously as it will end up (at some point). Hitting the assert:
as_context.cpp line 173
asASSERT(tld && tld->activeContexts[tld->activeContexts.GetLength() - 1] == ctx);
Now the fix for me obivously is since each thread is independent (aka any script classess assigned to a thread will always run on that thread) I can just create an engine per-group of thread and then the shared-local memory would be one per-thread. (Since they dont/cant communicate with each other anyways, but that seems bloated).
Im wondering if you can paint me a picture that clarifies the "Multiple threads may execute scripts in separate contexts.". Should i implement my own thread manager? (Looking into this now)
Thanks!