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 D5878BC37 for ; Sun, 10 Jan 2010 14:31:13 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0BAJ9lSUvRVdrVkGdsb2JhbACRUoIXhzU/AQEBAQkJDAcTA6ltgTKEE4VNAQIDBQWEJQQ X-IronPort-AV: E=Sophos;i="4.49,250,1262559600"; d="scan'208";a="41367334" Received: from mail-bw0-f213.google.com ([209.85.218.213]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jan 2010 14:31:13 +0100 Received: by bwz5 with SMTP id 5so13200881bwz.3 for ; Sun, 10 Jan 2010 05:31:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type:content-transfer-encoding; bh=IwYsWquJ+QmjOL/05NwSa8HKR6Sq4izUYJm68VGritg=; b=ZKSgh5m0evf31p3aBqJ8U2kEvGFogloRRuu3kZ0/NxHAQiTNe3HAIuD4vh+pGCDjty J9S7nk0Mq2PBt4PvlbyEacJeI6FbTFPAeTbSAUjxlgcN34Yl0rbFiwqnryrrajSRCUgD SukQiMYW85vscAWAknUMxNGEsJ3RqdQTDqCZk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=SlzMWFZFV/fhYE5lEBMqPdiDpY0CkcErUUUIh9HSTZt9jRUlfmdvUaS5TRtPYUuWT5 cBQRqoQH3t6t/npaIyS69wdMw0WJD0drEYAi/6NOpTqF+o1kavUyM/8AJkCXoGuYvPEQ gE/f1sPCoE+ZwbJ1AQx+OTI2YJRDbXz5J+uik= Received: by 10.204.24.5 with SMTP id t5mr1966897bkb.214.1263130270146; Sun, 10 Jan 2010 05:31:10 -0800 (PST) Received: from lemon (150-101-133-95.pool.ukrtel.net [95.133.101.150]) by mx.google.com with ESMTPS id 13sm8389095bwz.14.2010.01.10.05.31.07 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 10 Jan 2010 05:31:08 -0800 (PST) Date: Sun, 10 Jan 2010 15:31:05 +0200 From: ygrek To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] problem creating .cma library Message-Id: <20100110153106.bc7576e7.ygrekheretix@gmail.com> In-Reply-To: <4B48DAA7.3070400@citycable.ch> 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> X-Mailer: Sylpheed 2.5.0 (GTK+ 2.12.12; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Sat, 09 Jan 2010 20:36:07 +0100 Guillaume Yziquel wrote: > So if I want to call R code that multithreads with OCaml, I should write > something like > > > enter_blocking_section(); > > PROTECT(e = R_tryEval(Sexp_val(sexp_list), R_GlobalEnv, &error)); > > UNPROTECT(1); > > leave_blocking_section(); > > Am I correct? 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 the old pointer and get garbage. Put Sexp_val call before caml_enter_blocking_section(). -- ygrek http://ygrek.org.ua