Make sure the wakePend flag does not incur undefined behavior.

The wakePend flag currently has undefined behavior as multiple threads
read and write to it without a consistent locking mechanism.  This
switches writes and reads to use C++11's release-consume ordering
when available.  Without this patch, we have undefined behavior - which
is illegal with C++11.

The release-consume ordering is sufficient to guarantee atomicity
and the ordering of wakePend writes; other than that, it's a very
weak memory model.  In practice, this is a guarantee already provided
by all interesting architectures (it only generates different assembler
on DEC Alpha).

Fixes #167
Hi Brian,

That bit of code that was eliminated makes it much more probable that 
multiple duplicate messages will be sent. The lock is there to prevent 
duplicate messages while we are trying to figure out whether or not the 
poller thread is awake. It's all about time causality which is sort of 
wierd in threaded code. So, while it doesn't appear to make sense it winds 
up being crucial because we are trying to constrain two independent 
events (i.e. sending the message and checking if we should send the 
message - they are actually independant in a co-dependent way).

Andy

On Thu, 20 Nov 2014, Brian Bockelman wrote:

>> @@ -1158,12 +1159,11 @@ void XrdSys::IOEvents::Poller::WakeUp()
>>  // Send it off to wakeup the poller thread, but only if here is no wakeup in
>>  // progress.
>>  //
>> -   toMutex.Lock();
>> -   if (wakePend) toMutex.UnLock();
>> -      else {wakePend = true;
>> -            toMutex.UnLock();
>> -            SendCmd(cmdbuff);
>> -           }
>> +   bool isWakePend = CPP_ATOMIC_LOAD(wakePend, std::memory_order_consume);
>
> Note I eliminated the toMute locking here - I can't figure out what it'd be useful for.
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/xrootd/xrootd/pull/170/files#r20694995
>
> ########################################################################
> Use REPLY-ALL to reply to list
>
> To unsubscribe from the XROOTD-DEV list, click the following link:
> https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=XROOTD-DEV&A=1