1

Topic: UB?

Two flows, one pulls WaitAndPopInfo, the second Push. Whether the compiler  while (m_queue.empty ()) to while (true/false) can? typedef boost:: condition_variable condition_variable_t; typedef boost:: shared_ptr <condition_variable_t> condition_variable_ptr_t; boost:: mutex m_mutex; condition_variable_ptr_t m_ptrCondition; std:: queue <size_t> m_queue; bool boo:: TryPopInfo (size_t& areaId) {boost:: mutex:: scoped_lock lock (m_mutex); if (m_queue.empty ()) return false; areaId = m_queue.front (); m_queue.pop (); return true;} bool CAreaIdSink:: WaitAndPopInfo (stream_size_t& areaId) {{boost:: mutex:: scoped_lock lock (m_mutex); while (m_queue.empty() {boost:: system_time const timeoutAbsTime = boost:: get_system_time () + boost:: posix_time:: milliseconds (queueConditionTimeout); m_ptrCondition-> timed_wait (lock, timeoutAbsTime);}} return TryPopInfo (areaId);} void CAreaIdSink:: Push (cnt:: byte_array_ptr_t ptrBuf) {cnt:: CBufReader reader (ptrBuf); boost:: mutex:: scoped_lock lock (m_mutex); stream_size_t areaId = reader. ReadUlong (); m_queue.push (areaId); m_ptrCondition-> notify_all ();}

2

Re: UB?

I do not see here problems, access to queue is always protected. Presence  hinders to lead optimization which you described. Why the question was born?))

3

Re: UB?

Hello, uzhas, you wrote: U> I do not see here problems, access to queue is always protected. Presence  hinders to lead optimization which you described. Why the question was born?)) probably Friday-evening gave birth to this question

4

Re: UB?

Hello, dcb_BanDos, you wrote: _BD> Two flows, one pulls WaitAndPopInfo, the second Push. Whether the compiler  while (m_queue.empty ()) to while (true/false) can? A few cavils to the code (beside the point a question): * Pop on the basis of Try Pop with clearing and repeated capture  looks it is suboptimal * notify_all better to cause not under , under  only itself  in queue * Tajmaut on whom we do not quit waiting, and it is checked, whether who added suddenly in queue without notice. If except resulted Push in any way in queue do not add, it looks superfluous

5

Re: UB?

Hello, dcb_BanDos, you wrote: whether _BD> the compiler  while (m_queue.empty() to while (true/false) Can? timed_wait, as well as wait in itself releases , and then again capture. (In this release/capture also there are those barriers, inhibitory to think that m_queue.empty () did not exchange. boost:: mutex:: scoped_lock lock (m_mutex); while (m_queue.empty ()) {boost:: system_time const timeoutAbsTime = boost:: get_system_time () + boost:: posix_time:: milliseconds (queueConditionTimeout); m_ptrCondition-> timed_wait (lock, timeoutAbsTime);}