ImmutableOctet / glare

Glare: Open Source Game Engine written in Modern C++
MIT License
0 stars 0 forks source link

Implement an 'Entity Lock' type which pauses creation, destruction and thread/script updates while the lock is held #77

Open ImmutableOctet opened 4 months ago

ImmutableOctet commented 4 months ago

This lock would help prevent critical modifications of an entity from taking place while it is held. Once Entity Threads are running in parallel (e.g. on a thread scheduler), there is currently no guarantee that operations on other entities will be safe.

The idea here is to have a lock type that leverages RAII to ensure the work in the current scope is executed safely. Once the scope is exited, or if e.g. a loop iteration is completed, a different co_await is hit, etc. we can automatically unlock the entity, allowing other work to be performed.

Locks could be made more efficient by associating the entity's 'batch', rather than the entity itself -- we could then use a mutex/critical-section object per-batch.