...for use in a multithreaded network server.
I want to pass data around between multiple threads. Currently I'm using sockets, with the master thread blocking on select() and workers blocking on recv(), though I feel there probably are more advanced or prepackaged ways of handling this task in C++.
I would have worker threads waiting in a thread pool.
Then the master waiting on select (for both reads and writes).
As data comes the master adds jobs to the thread pool. As each job is added a thread wakes up executes the job and returns to the pool. This way you are not blocking threads waiting on specific ports with recv() and a fixed set of child threads can handle all incoming traffic.
Currentl libs that support this functionality in ready made objects:
libthread from plan9port includes a Channel struct that will be very similar; take note of Russ Cox's contribution to both plan9port and go-lang, and the libthread history:
Moving in a different direction, Luca Cardelli and Rob Pike developed the ideas in CSP into the Squeak mini-language [4] for generating user interface code. (This Squeak is distinct from the Squeak Smalltalk implementation.) Pike later expanded Squeak into the fully-fledged programming language Newsqueak [5][6] which begat Plan 9's Alef [7] [8], Inferno's Limbo [9], and Google's Go [13].
At a later point in Plan 9's history, it became too much effort to maintain infrastructure for two languages, so Alef was discontinued and the CSP constructs ported to C in the form of libthread.
So, since go channels are essentially a direct descendent from libthread, I don't think you'll find anything more similar :)
You can try the ACE library which ships with pipes and message queues which are specially suited for inter-thread communication.
**ACE stands for Adaptive Communication Environment*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With