Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a C or C++ library providing a functionality similar to Google Go's channels [closed]

...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++.

like image 523
lzm Avatar asked Feb 03 '10 07:02

lzm


3 Answers

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:

  • ACE: http://www.cs.wustl.edu/~schmidt/ACE.html
  • Poco: http://pocoproject.org/
like image 108
Martin York Avatar answered Nov 10 '22 23:11

Martin York


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 :)

like image 21
sqweek Avatar answered Nov 10 '22 22:11

sqweek


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*

like image 42
f4. Avatar answered Nov 10 '22 23:11

f4.