From: Costin Stefan <costins@auctionwatch.ro>
To: David Mentre <David.Mentre@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Thread and sockets
Date: Thu, 09 Aug 2001 12:20:34 +0300 [thread overview]
Message-ID: <3B7255E2.1C214D51@auctionwatch.ro> (raw)
In-Reply-To: <qtl8zgtbr80.fsf@pochi.inria.fr>
David Mentre wrote:
> Hello,
>
> I'm building a Caml client/server program using posix threads and
> sockets. Right now, I have 3 threads:
>
> 1. normal thread for user computation
>
> 2. a thread doing a blocking call to Unix.accept to setup new
> connections
>
> 3. a thread doing a blocking call to Thread.select (with infinite
> timeout) to get messages on opened connections
First of all read the man pages for read/write/select of the C system calls.
>
>
> I've observed that my design is bad and I have several race
> conditions. Worse problems are when I open and close connections. For
> example, if thread (3) is blocked and a new connection is opened by
> thread (2), thread (3) won't read new messages. I have similar problems
> when sockets are closed. How to do it properly?
A better approach (for thread 3) is :
do forever{
1. a select with a timeout.
2. When the select exit see if have data available or timeout occurred !
3. Then you can test if exists new accepted connections.
}
>
>
> I think I should open a dedicated thread for each new socket [1].
> However I don't know how to stop a thread waiting inside a blocking
> call. What happens if the remote part close the socket where a thread is
> doing a select (or a read). Does this thread get an exception?
When you try to read from a socket and the remote part close the socket
you will receive a SIGPIPE signal (try to handle this ;-) )
>
>
> I also don't know how to stop cleanly thread (2). Should another thread
> close the socket where thread (2) is doing an Unix.accept on?
>
> I would accept with pleasure any advice on this subjet.
>
> Best regards,
> david
>
> [1] At first, I did not choose this design to avoid creating zillions of
> new posix (i.e. kernel, on Linux) threads.
Who many simultaneous connections do you want to handle ?
Is enough a single thread for this ?
>
> --
> David.Mentre@inria.fr
> Opinions expressed here are only mine.
> -------------------
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-08-09 8:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-09 7:57 David Mentre
2001-08-09 9:20 ` Costin Stefan [this message]
2001-08-09 9:33 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3B7255E2.1C214D51@auctionwatch.ro \
--to=costins@auctionwatch.ro \
--cc=David.Mentre@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox