From: "Harry Chomsky" <harry@chomsky.net>
To: "Caml-list" <caml-list@inria.fr>
Subject: [Caml-list] Threads + Win32 API = crash
Date: Sat, 13 Apr 2002 13:46:36 -0700 [thread overview]
Message-ID: <002d01c1e32c$56ebe190$0200a8c0@harry> (raw)
[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]
I'm having trouble incorporating multithreading support into my OCaml-Win32
library. Basically, any program that uses OCaml threading and also invokes
a Win32 message loop will crash after a few seconds with an illegal attempt
to access memory at "0x00000001". This behavior is demonstrated by the
enclosed sample program, which is very simple and does not require my
OCaml-Win32 library.
I tried following the suggestion from the mailing list of adding "if not
(!Sys.interactive && signal=(-11))" to the preempt function, but it doesn't
seem to help.
I don't really know how to investigate this problem further. I've
determined that the problem goes away if I disable the tick thread, so
presumably it has something to do with the interaction of the tick thread
and the Windows message loop. I've also noticed that if I call
enter_blocking_section / leave_blocking_section in my C code, the behavior
changes: the program exits abruptly with no error message. By inserting
printf's, I've concluded that the GPF and/or abrupt exit do not occur during
execution of any of my C code. Beyond that, I don't know what to try.
Does anybody have any idea why OCaml's threads might be incompatible with a
Windows message loop, or how I can work on debugging this?
[-- Attachment #2: thr_c.c --]
[-- Type: application/octet-stream, Size: 730 bytes --]
#include <windows.h>
#include <caml/alloc.h>
#include <caml/callback.h>
#include <caml/custom.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
CAMLprim value make_window(value unit)
{
HWND hWnd;
hWnd = CreateWindow("EDIT",
"Generic Application",
WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
GetModuleHandle(NULL),
NULL);
ShowWindow(hWnd, SW_SHOWDEFAULT);
return Val_unit;
}
CAMLprim value msg(value unit)
{
MSG msg;
if (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return Val_unit;
}
[-- Attachment #3: thr.ml --]
[-- Type: application/octet-stream, Size: 199 bytes --]
let _ = Thread.create
external make_window : unit -> unit = "make_window"
external msg : unit -> unit = "msg"
let rec msg_loop () =
msg ();
msg_loop ()
let _ = make_window(); msg_loop ()
[-- Attachment #4: build.bat --]
[-- Type: application/octet-stream, Size: 82 bytes --]
ocamlc -custom -thread -o thr.exe unix.cma threads.cma thr.ml thr_c.c user32.lib
next reply other threads:[~2002-04-15 13:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-13 20:46 Harry Chomsky [this message]
2002-04-15 14:54 ` Xavier Leroy
2002-04-16 18:06 ` Harry Chomsky
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='002d01c1e32c$56ebe190$0200a8c0@harry' \
--to=harry@chomsky.net \
--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;
as well as URLs for NNTP newsgroup(s).