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

Listing 9.12: a question about locking #15

Open
alexsimonov999 opened this issue Jul 30, 2021 · 1 comment
Open

Listing 9.12: a question about locking #15

alexsimonov999 opened this issue Jul 30, 2021 · 1 comment

Comments

@alexsimonov999
Copy link

The line 61 is commented out in the repository (compared to the printed book):
// self->set_clear_mutex.unlock();
Why?
And it is suspicious that the order of set_clear_mutex and lk locking changes: initially lk is locked first (it must be locked before the call to interruptible_wait) and set_clear_mutex is locked second (in the ctor of custom_lock); but then the order changes in custom_lock::lock().
Is it really correct?

@alexsimonov999
Copy link
Author

And one more thing about the listing 9.12. In paragraph following the listing we read: "You can now check for an interruption without worrying about races. If the interrupt flag is set at this point, it was set before you acquired the lock on set_clear_mutex." But set_clear_mutex protects only access to thread_cond and a call to notify_all, not setting a flag. Maybe I'm wrong but as I understand, the flag can be set in some thread using set() function even if another thread has already locked set_clear_mutex.

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