From: ts@styx.enpc.fr (Thierry SALSET)
To: caml-list@margaux.inria.fr
Subject: IO in CSL threads
Date: Fri, 15 Mar 96 12:35:19 +0100 [thread overview]
Message-ID: <9603151135.AA09844@styx.enpc.fr> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2759 bytes --]
J'avais écrit dans un précédent message à propos des E/S dans un
programme CSL utiliant des threads :
> [English]
> This mail is about the Caml Special Light Thread module.
>
> Standard IO functions don't seem to work when used within CSL thread
> bodies.
>
> CML (Concurrent ML) offers a specific module for concurrent IO. Will CSL
> provide such a library ?
>
> [Français]
> Mes questions concernent l'utilisation du module Thread de Caml Special
> Light.
>
> Si je mets des opérations d'entrées/sorties dans le corps d'un thread,
> elles sont apparemment ineffectives. Est-ce que je me trompe ?
>
> J'avais l'habitude d'utiliser CML (Concurrent ML) qui fournit un
> module d'E/S spécifique. Est-il prévu d'inclure une telle bibliothèque
> dans CSL ?
Alors
1) Il existe en CSL un module ThreadIO
2) Mon programme (un petit exemple de la distribution de CML porté
"rapidement" en CSL) était le suivant :
let simple_comm () = let
ch = Event.new_channel()
and pr = print_string
in
pr "hi-0\n";
Thread.new (function () ->
begin
pr "hi-1\n";
Event.sync(Event.send ch 17);
pr "bye-1\n"
end) () ;
Thread.new (function () ->
begin
pr "hi-2\n";
Event.sync(Event.receive ch);
pr "bye-2\n"
end) () ;
pr "bye-0\n"
À l'exécution, il imprimait :
hi-0
bye-0
ce qui n'est pas ce à quoi on s'attend ! L'erreur provenait (merci à
Xavier Leroy pour son assistance éclairée) du fait que le programme
principal, après avoir créé les 2 threads, termine sans leur laisser le
temps de s'exécuter. Pour obtenir le résultat prévu il faut écrire :
let simple_comm () = let
ch = Event.new_channel()
and pr = print_string
in
pr "hi-0\n";
let t1 = Thread.new (function () ->
begin
pr "hi-1\n";
Event.sync(Event.send ch 17);
pr "bye-1\n"
end) () in
let t2 = Thread.new (function () ->
begin
pr "hi-2\n";
Event.sync(Event.receive ch);
pr "bye-2\n"
end) () in
Thread.join t1;
Thread.join t2;
pr "bye-0\n"
let _ = simple_comm ()
la fonction Thread.join permet d'attendre que les threads t1 et t2
terminent.
Donc Mea Culpa.
Je voudrais quand même signaler que, ayant l'habitude d'utiliser CML,
mon erreur provient du fait que le runtime CML fournit des services (par
exemple attendre que tous les threads soient terminés ou bloqués
définitivement avant de terminer la fonction principale) que n'offrent
pas CSL linké avec la bibliothèque de threads.
Bien sûr, cela ne dévalorise en rien la bibliothèque de threads de CSL.
Thierry Salset
CERMICS / ENPC
ts@cermics.enpc.fr
next reply other threads:[~1996-03-15 15:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-03-15 11:35 Thierry SALSET [this message]
-- strict thread matches above, loose matches on Subject: below --
1996-03-14 18:09 Thierry SALSET
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=9603151135.AA09844@styx.enpc.fr \
--to=ts@styx.enpc.fr \
--cc=caml-list@margaux.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