Thread-safety hazard in dwsUtils.AcquireUnifier function
Issue #225
resolved
Hello,
I have discovered a thread-safety problem in the AcquireUnifier function. The current implementation allows two threads to use the same TStringUnifier instance. Scenario: Thread 1 calls AcquireUnifier, reads vUnifiedStrings[0] contents and gets nil, but before really invoking InterlockedCompareExchangePointer() thread 2 releases its instance causing InterlockedCompareExchangePointer to fail (comparing vUnifiedStrings[0] to nil) but returning the real instance.
The proposed fix is to check comparand value not to be nil before invoking InterlockedCompareExchangePointer, the patch is attached.
Best regards,
Joe
Comments (2)
-
repo owner -
repo owner - changed status to resolved
Fixed Issue
#225race condition is AcquireUnifier interlocked exchange→ <<cset ffbc16b98f43>>
- Log in to comment
Interesting catch, thanks!