From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA11598 for caml-redistribution; Wed, 10 Sep 1997 11:11:56 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA10566 for ; Wed, 10 Sep 1997 10:19:10 +0200 (MET DST) Received: from yeti.didac-mip.fr (root@yeti.didac-mip.fr [130.120.37.103]) by nez-perce.inria.fr (8.8.7/8.8.5) with ESMTP id KAA28649 for ; Wed, 10 Sep 1997 10:19:08 +0200 (MET DST) Received: from yeti.didac-mip.fr (localhost [127.0.0.1]) by yeti.didac-mip.fr (8.8.5/8.8.5) with ESMTP id KAA05734 for ; Wed, 10 Sep 1997 10:17:24 +0200 Message-Id: <199709100817.KAA05734@yeti.didac-mip.fr> X-Mailer: exmh version 1.6.9 05/05/96 To: caml-list@inria.fr Subject: camlex/camlyacc + threads problem Reply-to: bouyssou@didac-mip.fr X-uri: http://www.didac-mip.fr/ Mime-Version: 1.0 Content-Type: text/plain Date: Wed, 10 Sep 1997 10:17:24 +0200 From: Olivier Bouyssou Sender: weis 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 %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