[thread.condition.nonmember]

# 32 Concurrency support library [[thread]](./#thread)

## 32.7 Condition variables [[thread.condition]](thread.condition#nonmember)

### 32.7.3 Non-member functions [thread.condition.nonmember]

[ð](#lib:notify_all_at_thread_exit)

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

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9537)

*Preconditions*: lk is locked by the calling thread and either

- [(1.1)](#1.1)

no other thread is waiting on cond, or

- [(1.2)](#1.2)

lk.mutex() returns the same value for each of the lock arguments
supplied by all concurrently waiting (via wait, wait_for,
or wait_until) threads[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9547)

*Effects*: Transfers ownership of the lock associated with lk into
internal storage and schedules cond to be notified when the current
thread exits, after all objects with thread storage duration associated with
the current thread have been destroyed[.](#2.sentence-1)

This notification is equivalent to:lk.unlock();
cond.notify_all();

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9558)

*Synchronization*: The implied lk.unlock() call is sequenced after the destruction of
all objects with thread storage duration associated with the current thread[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9563)

[*Note [1](#note-1)*:

The supplied lock is held until the thread exits,
which might cause deadlock due to lock ordering issues[.](#4.sentence-1)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9569)

[*Note [2](#note-2)*:

It is the user's responsibility to ensure that waiting threads
do not incorrectly assume that the thread has finished if they experience
spurious wakeups[.](#5.sentence-1)

This typically requires that the condition being waited
for is satisfied while holding the lock on lk, and that this lock
is not released and reacquired prior to calling notify_all_at_thread_exit[.](#5.sentence-2)

â *end note*]
