Opened 11 years ago

Closed 11 years ago

#5502 closed Patches (fixed)

race condition between shared_mutex timed_lock and lock_shared

Reported by: eliothorowitz@… Owned by: viboes
Milestone: Boost 1.49.0 Component: thread
Version: Boost Release Branch Severity: Showstopper
Keywords: Cc: eliot@…, viboes

Description

There is a potential race condition between 3 threads. Thread 1 - has a shared lock Thread 2 - goes into a timed_lock loop with a small sleep Thread 3 - tries shared_lock

Expected behavior: Thread 3 gets the lock when thread 2 fails to get exclusive lock.

What happens: based on timing, there can be a race condition causing a hang unless Thread 1 releases the lock.

Test and patch for boost-trunk that fixes the problem for me attached.

Attachments (2)

test.cpp (1.6 KB ) - added by eliothorowitz@… 11 years ago.
patch.5502 (587 bytes ) - added by eliothorowitz@… 11 years ago.

Download all attachments as: .zip

Change History (5)

by eliothorowitz@…, 11 years ago

Attachment: test.cpp added

by eliothorowitz@…, 11 years ago

Attachment: patch.5502 added

comment:1 by anonymous, 11 years ago

any update on this?

comment:2 by viboes, 11 years ago

Cc: viboes added
Milestone: To Be DeterminedBoost 1.49.0
Owner: changed from Anthony Williams to viboes
Status: newassigned
Type: BugsPatches

I have tested your patch and it works. Yes the issue is that when

    state.exclusive_waiting_blocked=false;

the shared_cond variable must be notified also.

I have committed this at [76084]. To be closed when merged to release.

Thanks for catching this and, of course, for the solution.

Last edited 10 years ago by viboes (previous) (diff)

comment:3 by viboes, 11 years ago

Resolution: fixed
Status: assignedclosed

(In [76346]) Thread: merge from trunk to fix #6141, #5594, #5040 and #5502.

Note: See TracTickets for help on using tickets.