You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
So the compare_exchange_weak is defined as follows:
bool compare_exchange_weak( T& expected, T desired,
std::memory_order success,
std::memory_order failure );
where it atomically compares *this == expected and
*this==expected ==> *this=desired;
*this!=expected ==> expected=*this.
My question is, I can make sense of the condition evaluating to true and why we would want it, but why would we want expected=*this when we get false? Where is this used (How did they get the idea to let expected=*this if *this!=expected?)
Lőrinczy Zsigmond
unread,
Aug 13, 2015, 7:20:53 AM8/13/15
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I think you are trying to ask about compare-and-swap mechanism,
which is an important tool in synchronization.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
The idea is to detect if 'expected' is unchanged since last time you
read it, and then update its value. If not, you might want to know what
has happened - like, has someone else changed the value? Into what?