0

I'm currently exploring boost::thread/threadpool and thread local storage basically to achieve a copy of one datagram to the job-queues for a pool of threads.

The current setup uses a 1:1 setup to copy loosely coupled one datagram from one thread to another using a custom notification queue. That queue does support multiple reader threads but every reader consumes the message.

I'm currently exploring to extend the queue by a thread_local_storage variant to get each datagram copied to the job-queue of each thread in the pool.

But I was wondering if boost might already support this kind of operation despite I coudln't find anything. Does boost out-of-the-box support a single copy to the local storage of every thread in a pool?

Thank you very much!

Hhut
  • 1,128
  • 1
  • 12
  • 24

1 Answers1

0

Why would you want a copy of the data to every thread? The only reason I can think of is, because the thread is making changes to the data that should not be visible to other threads. If no changes are made, simply pass a reference (aka pointer) to the data to every thread. If changes have to be made, pass a reference to every thread too and let the thread make a copy of the data. If you need the data to be released, when it's not used any more, use a shared pointer.

Thread local storage is mostly used to emulate old style static variables.

Torsten Robitzki
  • 3,041
  • 1
  • 21
  • 35
  • It's some sort of a filter chain... with N->N->N->N... many different (runtime depending) entities making iterative modification on datagrams. After the modification in each entity pushing them to the next one. I wish to implement not only the 1:1 connection between entities but also a 1:n connection. The problem with making the thread make the connection lies in the worker queues. One doesn't know if every thread had its share of data and when to pop() them from the actual queue. – Hhut Apr 10 '13 at 10:47
  • @Hhut Then use shared pointers to your datagrams. Push a share pointer to every queue where this datagram have to be processed. If the datagram is used on n queues, push the shared pointer to all of the queues. If a thread needs to make changes to the datagram, let the thread decide so and let the thread make a copy of the data. The only way, a worker thread gets a datagram should be by poping the shared data from a queue. – Torsten Robitzki Apr 10 '13 at 10:54