Behaviour of select in multi-threaded env

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

 



Hi All,

 

I am trying to write a multi-threaded echo server program. But facing some problem with it…

 

My main program creates a pool of worker threads and then accepts new connections from the clients. Main thread and worker threads share a queue that contains the file descriptor of the different clients.

After spawning the worker threads, main thread falls into the infinite loop where it accepts the new connections and put the client file descriptor in queue. Worker threads check in an infinite loop, if there is any data to receive from existing clients by using select call(passing NULL as timeout value, so it just hangs indefinitely), and if there is any then it will handle the request and send the same to the client like a typical echo server program. If there is a request to close a connection from client side then worker threads are responsible for deleting the corresponding file descriptor from queue.

 

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.

But, I am not able to understand why other threads select() didn’t get any response when the file descriptors change their status?

Isn’t this nice if either the thread library or the OS balance the work between different threads especially when all of them are waiting on similar condition?

 

--

Regards,

Gaurav Aggarwal

 


[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