Questions tagged «stdlist»


3
list :: empty()多线程行为?
我有一个列表,希望不同的线程从中获取元素。为了避免在列表为空时锁定保护该列表的互斥锁,请empty()在锁定之前进行检查。 如果对电话的呼叫在list::empty()100%的时间内都不正确,则可以。我只想避免崩溃或中断并发list::push()和list::pop()调用。 我是否可以肯定地认为VC ++和Gnu GCC有时只会empty()出错并且没有比这更糟的了? if(list.empty() == false){ // unprotected by mutex, okay if incorrect sometimes mutex.lock(); if(list.empty() == false){ // check again while locked to be certain element = list.back(); list.pop_back(); } mutex.unlock(); }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.