From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id BDE7EBC37 for ; Mon, 11 Jan 2010 19:01:28 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AooCAGb2SktV2gB5mWdsb2JhbACDXpd3AQEBAQEICwoHE69YjGyBK4IuVgSJJg X-IronPort-AV: E=Sophos;i="4.49,257,1262559600"; d="scan'208";a="41444010" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail3-smtp-sop.national.inria.fr with SMTP; 11 Jan 2010 19:01:28 +0100 Received: from [192.168.0.12] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id 5543C83431B; Mon, 11 Jan 2010 19:01:26 +0100 (CET) Message-ID: <4B4B6764.7060703@citycable.ch> Date: Mon, 11 Jan 2010 19:01:08 +0100 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: ygrek Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] problem creating .cma library References: <56670.41.177.16.252.1262195331.squirrel@41.177.16.252> <4B3BE288.4030701@citycable.ch> <3EE07409-9559-4B91-BA3E-8787D1378275@inria.fr> <4B47C201.7090201@citycable.ch> <4B47C59C.9080505@starynkevitch.net> <4B47C9BE.4060309@citycable.ch> <001f01ca9101$7ee76850$7cb638f0$@romulus.metastack.com> <4B486974.7060007@citycable.ch> <20100109125224.GC26610@annexia.org> <91a3da521001090600y2a456e3dg98200cd84d8bf082@mail.gmail.com> <4B48DAA7.3070400@citycable.ch> <20100110153106.bc7576e7.ygrekheretix@gmail.com> In-Reply-To: <20100110153106.bc7576e7.ygrekheretix@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 multithreads:01 ocaml:01 sexp:01 val:01 sexp:01 ocaml:01 val:01 pointer:01 overwritten:01 pointer:01 garbage:01 wrote:01 caml-list:01 ygrek a =C3=A9crit : > On Sat, 09 Jan 2010 20:36:07 +0100 > Guillaume Yziquel wrote: >=20 >> So if I want to call R code that multithreads with OCaml, I should wri= te=20 >> something like >> >>> enter_blocking_section(); >>> PROTECT(e =3D R_tryEval(Sexp_val(sexp_list), R_GlobalEnv, &error)); >>> UNPROTECT(1); >>> leave_blocking_section(); >> Am I correct? >=20 > I bet no. It is not safe to access block ocaml value > inside blocking_section. In this particular case Sexp_val(v) is Field > (v,0) whis in turn is v[0] or *v. So you read the pointer, then in > another thread GC moves things around and old copy of the pointed > value is overwritten, then you read the value through=20 > the old pointer and get garbage. > Put Sexp_val call before caml_enter_blocking_section(). OK. Thanks.... --=20 Guillaume Yziquel http://yziquel.homelinux.org/