Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "SooHyoung Oh" <shoh@miritek.com>
To: "Caml-List" <caml-list@inria.fr>
Subject: [Caml-list] Segmentation Fault on Mixing C and Ocaml thread
Date: Mon, 15 Dec 2003 13:51:12 +0900	[thread overview]
Message-ID: <005c01c3c2c7$1fc76eb0$63886bd2@hama> (raw)

[-- Attachment #1: Type: text/plain, Size: 1134 bytes --]

Hi!

On programming ocaml -> c -> ocaml applications using ocaml thread and C
pthread,
I met "Segmentation Fault" error on calling
ocaml thread -> c function -> c pthread -> callback() function.

Test examples are attatched.
Could anyone help me?

===============
(1) Ocaml thread -> c function
let thr_main ch () =
    let running = ref true in
    while !running do
    match (sync (receive ch)) with
        | Run -> run_cb ()
        | Run_segfault -> run_cb_segfault ()
        | Finish -> running := false
    done

(2) run_cb () is "OK"
CAMLprim value run_cb (value unit)
{
    CAMLparam1 (unit);
    printf("--- run_cb\n"); fflush(stdout);
    callback(g_closure, Val_unit);
    CAMLreturn (Val_unit);
}

(3) run_cb_segfault() generates "Segmentation Fault"
void *thr_main (void *arg)
{
 printf("--- thr_main\n");
 callback(g_closure, Val_unit);
}

void create_thr()
{
    pthread_t thr;
    pthread_create(&thr, NULL, thr_main, NULL);
}

CAMLprim value run_cb_segfault (value unit)
{
    CAMLparam1 (unit);
    printf("--- run_cb_segfault\n"); fflush(stdout);
    create_thr();
    CAMLreturn (Val_unit);
}

---
SooHyoung Oh

[-- Attachment #2: tst.tgz --]
[-- Type: application/x-compressed, Size: 1098 bytes --]

                 reply	other threads:[~2003-12-15  4:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='005c01c3c2c7$1fc76eb0$63886bd2@hama' \
    --to=shoh@miritek.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox