Boost logo

Boost Users :

Subject: [Boost-users] [boost.lockfree][spsc_queue] runtime sizing and producer's thread
From: Sampath Tilakumara (wolfie2x_at_[hidden])
Date: 2016-05-11 04:06:49


Hi,
Two questions on lockfree spsc_queue:

1. Can spsc_queue be dynamically (runtime) sized, and if so how do you
correctly do it?

  * Creating a mpmc queue with size 0 (i.e. queue<T>(0)) creates a
dynamically sizes mpmc queue, but doing the same for spsc queue doesn't.
  * creating a spsc queue with size 10 (i.e. queue<T>(10)) seems to create
a fixed sized ring buffer since at high transfer rates, push fails, however
the constructor code that takes the size asserts that it's runtime sized.
    explicit spsc_queue(size_type element_count): base_type(element_count)
    {
        BOOST_ASSERT(runtime_sized);
    }

  * documentation mentions lockfree::fixed_sized<> in policies, and can
also be found in (mpmc) queue.hpp, but it doesn't seem to be in
spsc_queue.hpp
  * all examples I could find on the internet (and documentation) was for
fixed size or for mpmc dynamic, but not for spsc dynamic.

2. In a normal (spsc using) program the producer will be a single OS
thread; however is it still safe to use on something like an actor
framework or fiber framework? (i.e. you only have a single producer object,
but it can actually be executed in different threads -- though strictly on
one thread at any given time).

for example in spsc_queue.hpp there's some code such as:
    bool push(T const & t, T * buffer, size_t max_size)
    {
        const size_t write_index =
write_index_.load(memory_order_relaxed); // only written from push thread

Refs on actors/fibers:
https://en.wikipedia.org/wiki/Fiber_%28computer_science%29
https://en.wikipedia.org/wiki/Actor_model

Thank you.
Sampath Tilakumara



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