Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Thread-per-socket vs select()
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Watt  
View profile  
 More options Dec 11 2002, 6:10 pm
Newsgroups: comp.programming.threads, comp.protocols.tcp-ip
From: st...@nospam.Watt.COM (Steve Watt)
Date: Wed, 11 Dec 2002 23:07:46 GMT
Local: Wed, Dec 11 2002 6:07 pm
Subject: Re: Thread-per-socket vs select()
In article <3DF7BD1E.CDF00...@webmaster.com>,
David Schwartz  <dav...@webmaster.com> wrote:

>"David M. Lloyd" wrote:

[ ... ]
>> When a select returns that a fd is ready, remove the fd from the set and
>> throw an event into the queue that states, for instance, fd "x" is ready
>> for reading, and go back to selecting again.  Then have a pool of threads
>> reading from the queue and processing requests.  After the threads read or
>> write to the appropriate fd, re-add the fd to the set using a mutex or
>> something, and then signal the thread that is selecting to reload its set
>> and select again (this is somewhat of a simplification but you get the
>> idea).

>> This way you only need one thread selecting, but all threads can operate
>> on the results of it.

>    Imagine you're handling 1,000 connections and you find work to do on
>100 of them. You will wind up restarting the 'select' 100-ish times as
>you add each one back to the set. In most cases, you're better off
>reading all the data before restarting 'select'. (Not necessarily
>processing it, just reading it.)

Note that he said to remove the fd from the set, which means that it
won't be selected for again "for a while" (until signalled ready again).

Additionally, if you process *all* of the notified fds in the loop
before calling select again (which is the only sensible thing to do),
you won't go through the loop anywhere near 100 times unless the
connections readied at exactly the right (wrong) times.

That model works pretty well for medium large values of file
descriptors, though I prefer the optimization that any thread can be
in the select, and will yank off all of the fds into the queue, start
working on the first one, and broadcast a cv to let the other threads
pick stuff off of the queue.  First one who finds the queue empty goes
back into select.
--
Steve Watt KD6GGD  PP-ASEL-IA          ICBM: 121W 56' 57.8" / 37N 20' 14.9"
 Internet: steve @ Watt.COM                         Whois: SW32
   Free time?  There's no such thing.  It just comes in varying prices...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.