Re: problem in select

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

 



On 5/19/06, tyler@xxxxxxxx <tyler@xxxxxxxx> wrote:
On Wed, May 17, 2006 at 09:59:38PM -0700, vikram b wrote:
> Hi All,
>           I dont know whether this is right place to put this ( Pls suggest if
> anybody know correct place)
> I am trying to use select system call to read from network socket. I have
> opened a socket and bind it on a port
> I have two threads (user space) each having a select , who is waiting on same
> Socket FD.
> When i send any data , only one of the thread is getting the data ...
> Is it normal ? Can i have any ways to have data to both select ?
>
> Any suggestion will be of great help
>
>
> thanks in advance
>
> vikram
>
Hi,

yes, it's normal. It's not the goal of select.

In fact, in your case, what you do is just reading from the socket in a
thread. The data is taken from the socket. Then the other do another
read and there's no data.

If you want the data to be received by the two processes, you should
share it (threads have the same adress space, it's easy to do without
any mechanism).

In your case, if 2 threads want the data received (let's say thread A
and thread B), you should do 3 threads :
the first thread which just reads from the socket. When data is
received, it wakes up threads A and B.


--
tyler
tyler@xxxxxxxx


I agree with tyler. I am not able to understand why in two threads you want to wait on same socket descriptor?
 
Once the data has been read from the socket it has been removed from the buffer.
 
since you are working with threads and both run on the same address process, i think you can shared the data between them once one of the threads reads it though notification mechanism.
 
I think theoritically it may possible with only two thread also. Whenever one thread receives the data let it notify other thread. I am not sure whether it is possible practically. If I am wrong Please correct me tyler.
 
Thanks
Manjunath Naik

[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