From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 792D3BC57 for ; Tue, 30 Nov 2010 13:55:47 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnABAC+D9EzAbSoIe2dsb2JhbACDUJEyjgsVAQEWIgQesXiRGg2BFIMzcwQ X-IronPort-AV: E=Sophos;i="4.59,280,1288566000"; d="scan'208";a="90402707" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 30 Nov 2010 13:55:47 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from first (e178036032.adsl.alicedsl.de [85.178.36.32]) (authenticated bits=0) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id oAUCtk1Z023614 for ; Tue, 30 Nov 2010 13:55:46 +0100 Received: by first (Postfix, from userid 1000) id 00B52441BD4; Tue, 30 Nov 2010 13:55:45 +0100 (CET) Date: Tue, 30 Nov 2010 13:55:45 +0100 From: oliver@first.in-berlin.de To: caml-list@yquem.inria.fr Subject: Re: Threading and SharedMem (Re: [Caml-list] Re: Is OCaml fast?) Message-ID: <20101130125545.GE1637@siouxsie> References: <4CF4B17C.7000703@planet.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4CF4B17C.7000703@planet.nl> User-Agent: Mutt/1.5.20 (2009-06-14) X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Spam: no; 0.00; in-berlin:01 threading:01 ocaml:01 0100,:01 bandel:01 gerd:01 stolpmann:01 bandel:01 gerd:01 stolpmann:01 libs:01 ocaml:01 libs:01 bigarray:01 genarray:01 On Tue, Nov 30, 2010 at 09:10:36AM +0100, Stephan Houben wrote: > On 11/29/2010 04:33 PM, Oliver Bandel wrote: > >Zitat von "Gerd Stolpmann" : > > > >>Am Montag, den 29.11.2010, 17:12 +0100 schrieb Oliver Bandel: > >>>Zitat von "Gerd Stolpmann" : > >>> > > >>>You use shared mem(?), but you link only to *.ml files, > >>>and I see no *.c there. > > >>>How can this be done? > >>> > >>>At least not via the libs that are shipped with OCaml?! > > Actually it can be done using the libs that ship with OCaml > (Unix and Bigarray), although it is not 100% POSIX : > > let create_shared_genarray kind layout dims = > let fd = Unix.openfile "/dev/zero" [Unix.O_RDWR] 0 > in let ar = Bigarray.Genarray.map_file fd kind layout true dims > in Unix.close fd; ar > > > The resulting bigarray object is shared among subsequent forks. Hmhhh... we started talking about Threads and SharedMem. You mean even fork.... hmhhh > This relies on the fact that mmap-ing /dev/zero is equivalent > to an anonymous mmap. > > http://en.wikipedia.org/wiki//dev/zero > > Well, at least it works on Linux. In APUE it's mentioned that memory mapped regions are inherited by a child, when forking it. So it should work on all Unix-systems too. There is one problem with this... when you have forked, then you obviously have separated processes and also in each process your own ocaml-program with it's own GC running... ..with such a mem-mapping trick (never used Bigarray, so I'm astouned it uses mmap) you then have independent processes, working on shared mem without synchronisation. This is a good possibility to get corrupted data, and therefore unreliable behaviour. So, you have somehow to create a way of communicating of these processes. This already is easily done in the Threads-module, because synchronisation mechanisms are bound there to the OCaml API and can be used easily. In the Unix module there is not much of ths IPC stuff... (A thread-specific GC for thread-specific variables would help here, making global locks only necessary when accessing global used variables. But I don't know if such a way would be possible without changing the GC-stuff itself.) Ciao, Oliver