This one is working as expected on my server. I tested most of the paths and it looks fine. Added comments to the previous path. Will like some double-checking and feedback if possible.
Can you help me/us understand the following a little better? If it is possible for two threads to simultaneously to have the same obj pointer and try to free the object, what prevents a seg fault* due to:
- thread #1 gets a pointer to obj A, then looses its time slice due to the OS scheduler before doing anything to the refcount or OBJ_CLEANUP_BIT
- thread #2 gets a pointer to obj A, refcount + OBJ_CLEANUP_BIT looks good, the memory for obj A gets freed
- thread #1 wakes up and tries to access/update the refcount + OBJ_CLEANUP_BIT in the freed memory
Thanks, Greg
* or worse than a seg fault: the memory is re-used for something else, then we overwrite it.
