Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.programmer > #950

Re: Non blocking socket operations in a multithreaded solution

From Rainer Weikusat <rweikusat@mssgmbh.com>
Newsgroups comp.unix.programmer
Subject Re: Non blocking socket operations in a multithreaded solution
Date 2011-07-15 22:08 +0100
Message-ID <8762n31ccd.fsf@sapphire.mobileactivedefense.com> (permalink)
References <ce3cabe7-ec94-4171-8335-94573394a10e@g3g2000prf.googlegroups.com>

Show all headers | View raw


itt ium <ittium@gmail.com> writes:
> I have a multithreaded program where various thread uses socket for
> sending and receiving data from network. I would not like to block my
> threads so I am thinking of following solution.
>
> Solution written below are for a single socket connection used for
> send and recv. In future, I might like to extend it for handling
> multiple connections.

Another option (if the required facilities for that are available) is
to use an edge-triggered I/O readiness notification mechanism and a
bunch of thread blocking in the notification routine. Whenever
something becomes ready, one of the threads gets a notification and
then goes off doing I/O until it that is either completed or would
block at which point it goes back into the notification routine until
something else becomes ready.

If you need to handle an arbitrarily large number of 'descriptors
which are ready' with a limited number of threads, each 'working'
thread would need to maintain some list of 'descriptors which are
ready' and do round-robin I/O and (while it is still busy) do
occasional non-blocking calls into the notification routine in order
to pick up new 'ready descriptors' nobody is looking after so far.

Back to comp.unix.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Non blocking socket operations in a multithreaded solution itt ium <ittium@gmail.com> - 2011-07-15 03:10 -0700
  Re: Non blocking socket operations in a multithreaded solution David Schwartz <davids@webmaster.com> - 2011-07-15 08:19 -0700
  Re: Non blocking socket operations in a multithreaded solution Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-07-15 22:08 +0100

csiph-web