Re: Re(2): [Repost] OTCountFreeBytes? (like OTCountDataBytes but for send)
Re: Re(2): [Repost] OTCountFreeBytes? (like OTCountDataBytes but for send)
- Subject: Re: Re(2): [Repost] OTCountFreeBytes? (like OTCountDataBytes but for send)
- From: Bryan Christianson <email@hidden>
- Date: Mon, 4 Feb 2002 23:06:53 +1300
At 10:32 PM -0800 2/3/02, Vincent Lubet wrote:
On Sunday, February 3, 2002, at 03:33 PM, Jens Bauer wrote:
About OT vs. BSD sockets, I'd really hate using fork() to replace the
notifier. I don't believe it would be possible to make threads run faster
than an interrupt. (My personal opinion; I grew up with interrupts)
With BSD sockets, the replacement of OT notifier is the select()
system call that allows for a process to wait for events on a set of
file descriptors at once -- only the simplest implementation use
fork().
Vincent
_______________________________________________
Alternatively, you can use pthreads, with the thread hanging on a
read (or some other blocking condition) until an event occurs (such
as a packet arrival).
This is analogous to the technique of using blocking reads/writes in
OT with the notifier simply handling SyncIdle events and the main
logic being in the thread that is waiting for the event, although I
believe that it has much better performance that the OT/SyncIdle
approach
The main advantage of pthreads over select is that you don't need to
build a state engine to distinguish between all your open
descriptors. Instead you can use stack based storage and its usually
a simpler model. Additionally, on a multi-cpu box you can take
advantage of all the CPU's
The disadvantage is that creating a new thread will use some
resource, so if you are expecting lots of short connections (e.g. as
in a web server) the overhead may be high. Of course you can always
allocate new connections to an existing (idle) thread, but this is
then additional complexity as you must keep track of the state of
each thread.
You also have to worry about all the locking issues associated with
multi-threaded software - debugging multi-threaded code can be
difficult as errors are often hard to reproduce :-(.
Regards
BC
--
Bryan Christianson
email: <
mailto:email@hidden>
Home Page: <
http://crash.ihug.co.nz/~bryanc>