HeliumProject / Engine

C++ Game Engine (Under Construction!)
http://heliumproject.org/
Other
442 stars 70 forks source link

Thread Hazard with Asset Reload #60

Open aclysma opened 10 years ago

aclysma commented 10 years ago

The object and proxy point to each other and maintain a ref count. We swap two pointers when swapping assets. There is a hazard that another thread could modify the reference counts on a proxy that no longer matches the object.

A potential solution is to have a global sync point for all threads every frame and do asset swaps during that sync. We could have a flag and a counter for threads that actively use the reference counting. A thread wanting to do a swap could add the swap to a list and set the flag. All threads would eventually need to sync, and when they see the flag, they would decrement their count and wait. The thread that decrements to zero would then do the swap and signal all other threads to start again, possibly with a condition.

We will need to take care that posix and windows threads have consistent behavior and ensure that all threads resume again.