Druntime without pthreads?
doob at me.com
Wed Oct 21 09:57:29 UTC 2020
On Tuesday, 20 October 2020 at 16:58:12 UTC, Severin Teona wrote:
> Hi guys.
> I have a curiosity, regarding  - I had encountered some
> "undefined reference" errors when trying to link the druntime
> (compiled for an embedded architecture) without some
> implementation of the POSIX thread calls (and other stuff too).
First, keep in mind that druntime and Phobos depends heavily on
the C standard library, the Posix APIs, Windows APIs and other
platform specific APIs. There's no list of what features or APIs
need to be supported by a platform. There's no general concept of
optional platform features, i.e. druntime will not automatically
adopt if your platform doesn't support a specific feature (like
threads). For example, on iOS (and related platforms)
`std.process` is not supported (because you're not allowed to
call `fork`). This is just hardcoded: if the platform is iOS,
don't provide `std.process`.
What I'm saying, if you modify druntime to remove threads and
locks, and resolve your undefined references, you might end up
with new undefined references for other symbols.
> My curiosity is what would change if I removed from the
> druntime everything that has to do with mutexes or threads.
> Would it be possible for the druntime to run and work properly
> on a microcontroller - where those concepts are not necessary?
> Could I just remove everything about synchronisation from the
> druntime, and classes or Garbage Collector to still work
The garbage collector will probably work (if you remove the
interaction with threads from it). Classes are a bit more
complicated, they have a hidden monitor field . There's also
the concept of synchronized classes . There's also the
`synchronized` statement . All these depend on
mutex/monitors/locks in some form (I don't know exactly how the
implementation works). Hopefully it should be fine as long as
your code doesn't use the `synchronized` statement or
synchronized classes. But all classes do come with a hidden
More information about the Digitalmars-d-learn