Title
Meaning of notify_all_at_thread_exit synchronization requirement?
Status
c++14
Section
[thread.condition]
Submitter
Pete Becker

Created on 2012-03-06.00:00:00 last changed 123 months ago

Messages

Date: 2013-04-20.08:17:49

Proposed resolution:

This wording is relative to N3376.

  1. Modify [thread.condition] p8 as indicated:

    void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
    

    […]

    -8- Synchronization: The call to notify_all_at_thread_exit and the completion of the destructors for all the current thread's variables of thread storage duration synchronize with ([intro.multithread]) calls to functions waiting on cond The implied lk.unlock() call is sequenced after the destruction of all objects with thread storage duration associated with the current thread.

Date: 2013-04-15.00:00:00

[ 2013-04-20, Bristol ]

Accepted for the working paper

Date: 2012-11-02.22:48:46

[ 2012, Portland: move to Review ]

The lk.unlock() refers back to the wording the previous paragraph.

Moved to review

Date: 2012-03-19.00:00:00

[ 2012-03-19 Hans Boehm comments: ]

I think the synchronization clause should just be replaced with (modulo wording tweaks):

"The implied lk.unlock() call is sequenced after the destruction of all objects with thread storage duration associated with the current thread."

as Jeffrey suggested.

To use this correctly, the notifying thread has to essentially acquire the lock, set a variable indicating it's done, call notify_all_at_thread_exit(), while the waiting thread acquires the lock, and repeatedly waits on the cv until the variable is set, and then releases the lock. That ensures that we have the proper synchronizes with relationship as a result of the lock.

Date: 2012-03-09.00:00:00

[ 2012-03-09 Jeffrey Yasskin comments: ]

I think the text should say that "notify_all_at_thread_exit and destructor calls are sequenced before the lk.unlock()", and leave it at that, unless there's a funny implementation I haven't thought of.

Date: 2012-03-06.00:00:00

notify_all_at_thread_exit has the following synchronization requirement:

Synchronization: The call to notify_all_at_thread_exit and the completion of the destructors for all the current thread's variables of thread storage duration synchronize with ([intro.multithread]) calls to functions waiting on cond.

The functions waiting on cond have already been called, otherwise they wouldn't be waiting. So how can a subsequent call to notify_all_at_thread_exit synchronize with them?

Also, "synchronizes with" is a relationship between library calls ([intro.multithread]/8), so it's not meaningful for completion of destructors for non-library objects. Presumably the intention wasn't so make library destructors special here.

History
Date User Action Args
2014-02-20 13:20:35adminsetstatus: wp -> c++14
2013-04-25 19:07:07adminsetstatus: voting -> wp
2013-04-20 08:17:49adminsetmessages: + msg6494
2013-04-20 08:17:49adminsetstatus: review -> voting
2012-11-02 22:48:46adminsetmessages: + msg6250
2012-11-02 22:48:46adminsetstatus: new -> review
2012-03-20 22:05:52adminsetmessages: + msg6071
2012-03-20 22:05:52adminsetmessages: + msg6070
2012-03-20 22:05:52adminsetmessages: + msg6069
2012-03-06 00:00:00admincreate