Attach and detach C threads to D runtime

David Soria Parra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 22 12:01:40 PDT 2014


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


More information about the Digitalmars-d-learn mailing list