Advertisement

Garbage collection

Started by September 20, 2010 06:45 AM
3 comments, last by cvet 14 years, 2 months ago
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();}
This is not really a "question" isn't it? :)

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.
Rainweaver Framework (working title)

IronLua (looking for a DLR expert)



Advertisement
Ok, question is: I must synchronize script contexts with garbage collector from Prepare to Execute, or can just Execute?

Code is simple example, in program this methods calls in different functions and more complicated.
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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.

This topic is closed to new replies.

Advertisement