Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condition.broadcast may not wake up all threads in native Windows build #5013

Closed
vicuna opened this issue Mar 31, 2010 · 2 comments
Closed
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 31, 2010

Original bug ID: 5013
Reporter: omion
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2011-05-29T10:19:33Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.11.1
Fixed in version: 3.12.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @ygrek

Bug description

If two threads are waiting on a condition, Condition.broadcast should wake both of them up. However, if the first thread to be awoken waits on the same condition again it may be woken up again instead of the other thread.

I marked reproducibility as random since it depends on threads, but it happens about 50% of the time.

Linux and bytecode-Windows seem to be immune from this problem.

Additional information

The attached code can display the problem. Each line of the output begins with the thread which is printing it. two threads "t1" and "t2" wait on condition "c". The main thread then broadcasts the condition, which SHOULD wake up both threads eventually. On Linux this program always outputs:
1: waiting first
2: waiting first
0: BROADCAST
2: going from broadcast; waiting second
1: going from broadcast; waiting second

indicating that both threads woke up. On Windows the program may return:
1: waiting first
2: waiting first
0: BROADCAST
1: going from broadcast; waiting second
2: going from broadcast; waiting second

which is also correct (the threads were woken up in the opposite order as on Linux, but that doesn't matter). However Windows may also return the following:
1: waiting first
2: waiting first
0: BROADCAST
2: going from broadcast; waiting second
2: going from broadcast a second time

basically the broadcast woke up thread #2 TWICE, without waking up thread #1 at all. If this were a real program which was waiting on thread #1 to continue it would deadlock.

File attachments

@vicuna
Copy link
Author

vicuna commented Apr 1, 2010

Comment author: omion

Actually, after further testing, it looks like it only occurs in 64-bit Windows compiles. My 32-bit compilation of the code seems to work properly...

@vicuna
Copy link
Author

vicuna commented Apr 27, 2010

Comment author: @xavierleroy

The Win32 implementation of condition variables was indeed incorrect w.r.t. Condition.broadcast. Reimplemented condition variables under Win32 in a way that should conform to POSIX semantics. Will go in 3.12.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants