RE: Behaviour of select in multi-threaded env

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2007-07-19 at 15:18 +0530, Gaurav Aggarwal wrote:
> From: Bernd Petrovitsch [mailto:bernd@xxxxxxxxx] 
> Sent: Thursday, July 19, 2007 2:12 PM
> To: Gaurav Aggarwal
> Cc: kernelnewbies@xxxxxxxxxxxx
> Subject: Re: Behaviour of select in multi-threaded env
> 
> On Wed, 2007-07-18 at 21:25 +0530, Gaurav Aggarwal wrote:
> [...]
> > But the problem is that, only one thread was doing all the work
> > (handling all the connections), other threads are just blocking in
> > select()  system call even when all of them have the same
> > information. 
> 
> How many select(2)s are waiting on one given diledescriptor?
> - one or
> - more than one?
> 
> More than one ... actually there are three worker threads and all of
> them are waiting on same set of file descriptors but only one thread is
> getting the signal fron OS/library

Yes, because then it is up to the kernel (who decides which of the
waiting select(2)s is triggered) to decide which task/thread/process
(and yes, the waiting select(2) could perfectly by different processes).

BTW you have with that potential bugs waiting: If 2 threads got wakened
up on the same file descriptor, probably both will read data from it and
if you get lucky, it is garbled enough that the application notices it.

So IMHO you should give each thread a disjunctive set of file
descriptors.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services



--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux