
I've sketched out a Haskell interface to a C++ toolkit that uses threads. It's the Haiku (BeOS) platform API (BeOS is an obscure OS from the '90s, Haiku is a pretty faithful recent open source re-implementation.) The API is fairly obvious and I imagine much like others that support windowed graphic interfaces. You have your Window class that spawns a thread, and various virtual methods of that class support program interface with the events involving that window. The curious thing is that I can get this to work with my example program only if it is NOT linked with -threaded. If linked with -threaded, when the application comes up I have 4 threads: the main thread and window thread, and two threads apparently created by the Haskell runtime. Shortly (but not immediately) after the first callback from the window thread, the window thread quietly dies. Callbacks from the main thread work fine. Linked without -threaded, I have only the 2 natural threads, and the window thread can call back apparently without problems. I imagine I'm at fault somewhere in this, since I am also responsible for the GHC port to Haiku, but just wondering if this suggests an obvious course of inquiry to anyone. I assume it's not working as intended, as from the documentation I would rather have guessed that -thread would be required in this situation. thanks! Donn Cave, donn@avvanta.com

Donn Cave
I imagine I'm at fault somewhere in this, since I am also responsible for the GHC port to Haiku, but just wondering if this suggests an obvious course of inquiry to anyone. I assume it's not working as intended, as from the documentation I would rather have guessed that -thread would be required in this situation.
Could it be that Haiku is expecting BeOS threads but you give it UNIX processes? It might be that all threads serving a GUI app must be part of the same team. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

Quoth Achim Schneider
Donn Cave
wrote: I imagine I'm at fault somewhere in this, since I am also responsible for the GHC port to Haiku, but just wondering if this suggests an obvious course of inquiry to anyone. I assume it's not working as intended, as from the documentation I would rather have guessed that -thread would be required in this situation.
Could it be that Haiku is expecting BeOS threads but you give it UNIX processes? It might be that all threads serving a GUI app must be part of the same team.
No, I'm not creating any other threads or processes, other than the window thread that's implicitly created by the window API. If it helps, a coarse outline of the API: class W : public BWindow { W(...params...): BWindow(...params...) { ... initialize graphic elements } void MessageReceived(BMessage *msg) { ... respond to event by calling Haskell function // will lead to thread abort if linked -threaded. } }; main thread: W *w = W(...params...); w->Show(); // thread spawned by this member function. I haven't written any code to support the above - BWindow::Show() was provided by the platform. I did of course have to do a lot of hacking around with FFI stuff. The BWindow-derived object stores a table of foreign wrapper pointers to callback functions that take a StablePtr, etc., and I wouldn't know where to start thinking about that works with garbage collection. Donn Cave, donn@avvanta.com
participants (2)
-
Achim Schneider
-
Donn Cave