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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E15C1BCA2 for ; Fri, 12 Aug 2005 16:56:25 +0200 (CEST) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.199]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7CEuPjx015397 for ; Fri, 12 Aug 2005 16:56:25 +0200 Received: by rproxy.gmail.com with SMTP id a36so560997rnf for ; Fri, 12 Aug 2005 07:56:24 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=jLGwC6JcnWOj5s9TnivwHHXNTKcUWh2cDbjZLXfq/pRlcNlhBGBFcapM4RiPwVOtQsRMOkHGc3V0/JZErG7q5prEXQUbNXrTK/zje4/BH1/GF//4SfbdC6w+sZnt9M/037jmkxrmuEykIEThWjwCgCdzQ6smvX8xFjWOR1yni+A= Received: by 10.39.2.8 with SMTP id e8mr1073365rni; Fri, 12 Aug 2005 07:56:24 -0700 (PDT) Received: by 10.38.209.44 with HTTP; Fri, 12 Aug 2005 07:56:24 -0700 (PDT) Message-ID: Date: Sat, 13 Aug 2005 02:56:24 +1200 From: Jonathan Roewen To: caml-list@yquem.inria.fr Subject: [Caml-list] Implementing co-op threads in ocaml Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Miltered: at nez-perce with ID 42FCB899.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 threads:01 ocaml:01 ocaml:01 threading:01 systhreads:01 char:01 stack:01 stack:01 char:01 pointer:01 pointer:01 struct:01 heap:01 pointers:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 Hi, I have a few questions about how to allocate some C-side values in an ocaml type, for the purposes of implementing custom threading in a native app. After reading through some systhreads code, I've come up with the notion that the following 5 C-land values are probably key to making this work: char * bottom_of_stack; /* Saved value of caml_bottom_of_stack */ unsigned long last_retaddr; /* Saved value of caml_last_return_address = */ value * gc_regs; /* Saved value of caml_gc_regs */ char * exception_pointer; /* Saved value of caml_exception_pointer */ struct caml__roots_block * local_roots; /* Saved value of local_roots */ I've been trying to make sense of all the rules and things in the ocaml manuals for storing C data in an ocaml value, but am having some trouble. Especially with gc_regs, which I assume points to a value inside the ocaml heap. For the purposes of the rules that everything being on a 32-bit boundary, all the pointers would be fine, and the fact that last_retaddr is a 32bit value, all this would be fine. Since I'm doing co-op threading primarily in OCaml, I'm also assuming I don't need to create custom stacks for each thread (such as in C), and having to swap stacks; therefore, access to ocaml global values/functions should be fine. Is this assumption correct? Am I also correct to think that the only real trick to this would be making sure the GC scans all thread roots? If say my threads are in a list, I could have an external function that scans the thread, and just iter over this list? I'm especially interested in how to correctly handle the C-specifics for storing the pointers and things, but other feedback is also welcome =3D) Jonathan