Skip to main content
gamedev.net
🔒 Locked

C++ Pipe

Started by dali Aug 23, 2008 at 1:00 PM 3 replies 1.5k views
Original Post
dali
dali
Hello! I have many threads which create tasks and send these tasks to a pipe. My question is how to efficiently create this pipe that no lock occurs when more threads simultaneusly add a task. Should the threads assemble more tasks and send this block of data to the pipe that less adding occurs? Is there already a lockless pipe in c++? What would be the best way? Thank you a lot!!!
Gaudeamus igitur, iuvenes dum sumus!
frob
frob
Most systems provide a message queue, mailbox, or similar functionality to transmit stuff between threads/tasks without worrying about locking. You can send a message to the queue, and the thread/task can occasionally check it to see if there are messages.

>> Is there already a lockless pipe in C++?

No, the language currently does not have any knowledge of threading, concurrency, or any synchronization or locking mechanisms. All of that functionality is added by your own system libraries, either directly through OS calls, or indirectly through pthreads or Boost or other libraries.
Shannon Barber
Shannon Barber
Use 1 pipe per thread if you want no locks.
Otherwise something is going to have to lock to serialize the data into the 1 pipe.
You could use a lock-less list to serialize the data into 1 stream - many thread dump to the list. Then 1 thread sucks the list and pushes it out the pipe (using a semaphore to block/unblock as needed).
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
dali
dali
Thank you all very much!
Gaudeamus igitur, iuvenes dum sumus!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.