Re: socket lock in multithred programming

From: Ku Jaguk (jkku_at_softeleware.com)
Date: 09/29/05


Date: Thu, 29 Sep 2005 11:26:19 +0900

First, it's not the homework.

I used to make a socket program, even multithreaded socket program and i
have read enough books about the socket i think.
Even Stevens book socket programming, I don't think it mentions about one
thread only reading to and the other thread only writing from the same
socket descriptor.
I have tried all the case of socket server processes in real environment
those are mentioned in Stevens socket programming 1, such as single process
server, dynamic fork, pre-fork, dynamic spawning thread, pre-threaded, even
i anylized the current Apache web server, Hybrid multithreaded socket which
has pre-fork and pre-thread.

you said i should look at the socket man page, i just read all man pages but
i can not find about it.

I am sincerely saying that i can not find about what i mentioned. and i
really curious about it.

If the threads doesn't need to lock the same socket description, i think it
would be more efficent to have two threads hanle the socket IO, because i
useally making a client socket program which has limited connection to
server, and i don't like polling the socket.

Thanks in advance,

Jaguk Ku

"Pascal Bourguignon" <spam@mouse-potato.com> wrote in message
news:871x39gxq5.fsf@thalassa.informatimago.com...
> "Ku Jaguk" <jkku@softeleware.com> writes:
>
>> Hi there,
>>
>> I am making a multithreaded process.
>> it has a tcp/ip socket and two threads, one thread for sending message to
>> socket, the other for receiving a message from socket. i don't know it's
>> a
>> good architecture or not for socket programming.
>>
>> the question is
>> 1. Does it need to lock(for example mutex lock) the socket in both
>> threads
>> whenever sending to and receiving from socket?
>>
>> 2. If it need to lock the socket, why?
>>
>> 3. If it doesn't need to lock the socket, why?
>>
>> 4. If it doesn't need to lock the socket, which thread should close the
>> socket? if one thread close the socket and set socket fd with -1 value
>> without locking it, what happend to the other thread when it access the
>> socket fd?
>>
>> 5. If it need to lock the socket, i think i don't need to make two
>> threads,
>> just one thread is ok. am i right?
>
> Sounds like homework.
>
> Try reading some more man pages and course material.
> Start with:
>
> man 2 socket
> man 7 socket
> man 2 close
>
> and some tutorial about unix, processes, file descriptors and
> threads. (Use google).
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> Small brave carnivores
> Kill pine cones and mosquitoes
> Fear vacuum cleaner



Relevant Pages

  • Re: socket lock in multithred programming
    ... > I used to make a socket program, even multithreaded socket program and i ... A file descriptor is a handle for a kernel space structure. ...
    (comp.unix.programmer)
  • unblocking a port
    ... I have a simple socket program which needs to connect and send an xml stream ... private Socket TcpSocket; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can you recommand a book about socket(tcp/ip) programming for windows CE
    ... there really are few differences for the average socket program. ... If you have to have a book to make you feel better, WinSock on Windows CE is ...
    (microsoft.public.windowsce.embedded)
  • Re: Perl Sockets Parent/Child Problem
    ... Ken Browning wrote: ... > with it, but my program is a socket program, thus the title... ... But your problem is not a socket problem, ...
    (comp.lang.perl.misc)
  • Re: kqueue disable on delivery...
    ... The first is EV_DOD, aka disable on delivery. ... some in-kernel lock overhead. ... necessity to guarantee that the socket (both events - EVFILT_READ ... use the oneshot only model where a socket is deleted from port on delivery. ...
    (freebsd-arch)