Threads vs Select (was Re: Re(2): [Repost] OTCountFreeBytes? (like OTCountDataBytes but for send))
Threads vs Select (was Re: Re(2): [Repost] OTCountFreeBytes? (like OTCountDataBytes but for send))
- Subject: Threads vs Select (was Re: Re(2): [Repost] OTCountFreeBytes? (like OTCountDataBytes but for send))
- From: Duane Murphy <email@hidden>
- Date: Mon, 4 Feb 2002 08:19:19 -0800
--- At Mon, 4 Feb 2002 23:06:53 +1300, Bryan Christianson wrote:
>
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
How do you break a thread that is waiting on a read? Or rather what
happens when a thread is killed waiting on a read? Or how do you kill a
thread waiting on read?
If you have a thread waiting on a read and the program wants it to stop
in order to quit or because the user cancelled the request, what is the
right way of doing that?
Seems like just killing the thread doesnt properly unwind the stack so
some things might be left un-clean.
What is the right technique for this?
...Duane