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 Variable - Incorrect Locking in main-two-cvs-while? #37

Open
ambareeshsrja16 opened this issue Jul 10, 2021 · 0 comments
Open

Comments

@ambareeshsrja16
Copy link

ambareeshsrja16 commented Jul 10, 2021

Ran main-two-cvs-while with the following arguments:
./main-two-cvs-while -l 5 -m 2 -p 1 -c 1 -v

1 producer, 1 consumer, buffer size of 2 and loops 5 times.

Every alternate run produces the following output:
image

Isn't the sequence of c0, p0, c1, c2, p1, p4 .. an incorrect locking mechanism?

Screenshot of the code:
image

Consumer acquires lock at c1, sleeps at the while loop at c2 and then we context switch to the producer, which seems to acquire the lock at p1? If consumer hasn't released the lock yet, how's this possible? It'd have made sense if the consumer had gotten to c3 (cond_wait - where it'd sleep and release the lock which the producer could have then acquired in p1)

Am I missing something obvious?

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

No branches or pull requests

1 participant