Boost logo

Boost Users :

Subject: Re: [Boost-users] circular buffer in a multithreaded program
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-04-24 02:44:41


2014-04-23 1:52 GMT+04:00 Sebastian Gesemann <s.gesemann_at_[hidden]>:
<...>

> My guess is that "working" with an iterator while concurrently doing an
> erase_first/resize creates a data race -- possibly because an iterator
> tries to read some of circular_buffer's state which is modified via
> erase_first and/or resize. But that's just a guess. I did not check the
> circular_buffer implementation too closely.
>

You are right. Iterator holds a pointer to circular_buffer and accesses
some of its internals.

However it is safe to use only iterators and overwrite independent parts of
circular_buffer. All the operations with iterators do not modify internals
of circular_bufer.
So if you change cb.erase_first(n)/cb.resize(cb.capacity()) to iterator
operations there must be no problems. Though I thinks that's what you have
done in case of custom vector-based data structure.

Thanks for the investigation!

-- 
Best regards,
Antony Polukhin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net