Deadlock in Persistent Streams
Borland's Object Windows Library for the modern age
Brought to you by:
jogybl,
sebas_ledesma
Before setting the ticket status to "pending", please check in the fix and post an update including a link to the revision, e.g. "This issue has been fixed [r42]".
Related
Commit: [r42]
Last edit: Vidar Hasfjord 2015-03-11
Hi Igor, are you working on this bug?
There is a problem with your proposed fix:
This code sequence allows multiple threads to enter the if-clause at once, leading to multiple initialisation of
Types. Naively, we may handle this issue using double-checking:However, this may still not be 100% safe due to the way the compiler and CPU might rearrange instructions and memory accesses. See Double-checked locking at Wikipedia for an explanation of the issues.
That said, I think this solution is good enough. It is already unsafe to multi-thread OWLNext (see Multi-threading and OWLNext), and we advice against it, so the slight possibility of a problem here does not matter much.
Related
Wiki: Multi-threading_and_OWLNext
By the way, the existing preceding code is not thread-safe either:
Here, multiple threads may enter the if-clause at the same time. Also, the compiler may rearrange instructions so that Lock is assigned before completing the constructor, after which a secondary thread may skip the if-clause and proceed to use Lock pointing to an uninitialised (or partially initialised) object.
This issue was fixed in [r3004], and merged into 6.40 in [r3005].
Note the multi-threading issues pointed out in the preceding posts. The fix does not attempt to handle these issues. It only circumvents the reentrancy deadlock.
Related
Commit: [r3004]
Commit: [r3005]
Last edit: Vidar Hasfjord 2015-04-16