Attach and detach C threads to D runtime

2014-05-22 Thread David Soria Parra via Digitalmars-d-learn
Hi,

I am currently writing a fuse wrapper for D and try to support fuse
multithreading which is based on pthreads. However fuse doesn't offer me
a proper way to hook into the creation and joining process of threads.

I can attach the threads created by libfuse but cannot find a way to
properly detach the threads from the runtime:

My current approach:
  Whenever a fuse function is called I check with a thread local
  variable "isAttached" if the current thread is already attached, if
  not, I call thread_attachThis.

This works fine and let the GC properly suspend the threads, however
when fuse_main() returns all threads are gone but the Druntime still
tracks the now non-existant threads anymore. When the GC does a final
sweep it will crash. Any ideas how to unregister my threads beforehand.

I know that thread_detachByAddr exists, but the Thread object from
Thread.getAll or Thread.opApply doesn't expose the thread address.

Hints?

- Thanks,David


Re: Haskell calling D code through the FFI

2014-08-05 Thread David Soria Parra via Digitalmars-d-learn

On Monday, 4 August 2014 at 20:48:09 UTC, Jon wrote:

For reasons I don't completely understand, you also need a fake 
main function, dummy.d:


void main(){}



Note that this is not necessary if you compile with -lib e.g.:

  dmd -lib -oflibtest.a test.d

and then

  ghc Main.hs --make -omain libtest.a

I don't have gdc or ldc installed but as far as I know ldc has a 
-lib flag as well.


Re: Haskell calling D code through the FFI

2014-08-06 Thread David Soria Parra via Digitalmars-d-learn
Jon via Digitalmars-d-learn  writes:

> So that does indeed solve some of the problems.  However, using this
> method, when linking I get two errors, undefined reference rt_init()
> and rt_term() I had just put these methods in the header file.  If I
> put wrappers around these functions and export I get the rt_init,
> rt_term is private.
>

rt_init is part of druntime. You need to link druntime into your program
in order to make it work.