Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Olivier Bouyssou <bouyssou@yeti.didac-mip.fr>
To: caml-list@inria.fr
Subject: camlex/camlyacc + threads problem
Date: Wed, 10 Sep 1997 10:17:24 +0200	[thread overview]
Message-ID: <199709100817.KAA05734@yeti.didac-mip.fr> (raw)

English translation below.

J'ai un probleme lorsque j'utilise une fonction de parsing dans plusieurs 
threads

Voici l'exemple qui parse une liste de crenaux horaires :

Le lexer :

--
{
open Horloge_parser
} 
rule token = parse
   [' ' '\t' '\n']          { token lexbuf }
|  ['0'-'9']['0'-'9']       { INT(int_of_string(Lexing.lexeme lexbuf) }
|  ['0'-'9']                { INT(int_of_string(Lexing.lexeme lexbuf) }
|  ':'                      { PP }
|  '-'                      { TIRET }
|  eof                      { EOF }
--

Le parser :

--
%{
exception Incorrect_minute
exception Incorrect_hour
let test_minute m = if m < 0 || m > 59 then raise Incorrect_minute
let test_heure  h = if h < 0 || h > 23 then raise Incorrect_hour
%}
%token <int> INT
%token PP
%token TIRET
%token EOF
%start main
%type <(int * int) list> main
%%
main:
  EOF { [] }
| liste_intervalle EOF { $1 };

liste_intervalle:
  intervalle { [$1] }
| liste_intervalle intervalle { $2::$1 };

intervalle:
  heure TIRET heure { ($1,$3) };

heure:
  INT { test_heure $1; $1*60 }
|  INT PP INT { test_heure $1; test_minute $3; $1*60+$3};
--  


Et le programme qui utilise le parser : 

--
let mutex = Mutex.create () 
  
let task () =
  while true 
  do
    let lexbuf = Lexing.from_string "0-23:59" in
    Mutex.lock mutex ;
    Horloge_parser.main Horloge_lexer.token lexbuf ;
    Mutex.unlock mutex ;
    if (Random.int 100) = 10 then ThreadUnix.sleep 1 ;
  done 
    
let main () =
  for i = 0 to 100 do Thread.create task () done ; 
  while true do ThreadUnix.sleep 1 done ;;

main () ;;
--

Le probleme est que sans le mutex j'obtient des Parse_errors. 

-----------------------------------------------------------------------------
English summary :

I've a problem when I use a parser in multiple threads. If the calls to the 
parser are not enclosed by a mutex, there are parse errors. ( See example in 
french version )


-----------------------------------------------------------------------------
-- 
Olivier Bouyssou (F1NXH), Didactheque Regionale          bouyssou@didac-mip.fr
Universite Paul Sabatier 118, route de Narbonne           31062 TOULOUSE Cedex
Tel : +33.5.61.55.65.74                                Fax : +33.5.61.55.65.71








             reply	other threads:[~1997-09-10  9:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-10  8:17 Olivier Bouyssou [this message]
1997-09-18 14:18 ` Xavier Leroy
1997-09-16 14:25 Thierry Bravier
     [not found] <199709231254.OAA20307@yeti2.didac-mip.fr>
1997-09-25 12:19 ` 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=199709100817.KAA05734@yeti.didac-mip.fr \
    --to=bouyssou@yeti.didac-mip.fr \
    --cc=bouyssou@didac-mip.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