Question about garbage collection in multithreading.
Quote: Do not execute the garbage collector while other script threads are executed, as the garbage collector may be traversing the reference graph while the objects are modified by the other threads.
Question in code:
void func1(){ Mutex.Lock(); engine->CollectGarbage(...); Mutex.Unlock();}void func2(){ Mutex.Lock(); // Must lock here? context->Prepare(...); ... Mutex.Lock(); // Or can here? context->Execute(); Mutex.Unlock();}
However, if I understand what you mean, you really need a stop-the-world collector - that is, you don't really want any script to run when there's a garbage collection. So lock as eagerly as possible before running a script, and be wary of race conditions.
You can probably keep the Mutex.Lock() just before the Execute() call.
But do you really have the need to run the garbage collector in a different thread while scripts are running? Are the scripts running at all times? If not, then why not run the GC when the scripts aren't running anyway.
No, i don't need run GC when some script executed, and ask where begins "while other script threads are executed" - on asIScriptContext::Prepare or asIScriptContext::Execute, to place my Mutex.