Alfredo Braunstein wrote: > Angus Leeming wrote: > >> There is still no need to have bucket2_ as a class member... >> >> void LoaderQueue::emptyBucket() >> { >> cout << "emptying bucket" << endl; >> std::queue<Cache::ItemPtr> tmp = bucket1_; >> while (!tmp.empty()) { >> addToQueue(tmp.front()); >> tmp.pop(); >> } >> } > > Humm... I think that this doesn't cut it, you cannot copy bucket1_ without > locking it (touch() can be accessing it at the same time, you can end up > with a partially updated queue). If we use swap(), then is merely swapping > pointers, that is supposed to be threads-safe (apart from being faster). > But I'm not at all a threads guru (first application really)... So correct > if I'm wrong.
Ok, so: std::queue<Cache::ItemPtr> tmp; swap(bucket1_, tmp; Still no need to pollute the class interface... Thanks for the info about threads. -- Angus