std::atomic<T>
and std::condition_variable
both have member wait
and notify_one
functions. In some applications, programmers may have a choice between using either for synchronization purposes. One goal with these wait
functions is that they should coordinate with the operating system to minimize spurious wakeups. That is, the operating system should avoid waking the wait
-ing thread until notify_one
or notify_all
are called.
On my machine, sizeof(std::atomic<T>)
is sizeof(T)
and sizeof(std::condition_variable)
is 72. If you exclude std::atomic<T>
's T
member, then std::condition_variable
reserves 72 bytes for to serve its synchronization purposes while sizeof(std::atomic<T>)
reserves 0 bytes.
My question: should I expect different behavior between std::condition_variable
's and std::atomic<T>
's wait
functions? For example, should std::condition_variable
have fewer spurious wakeups?