sleeping vs sched_yield

Stanislav Blinov stanislav.blinov at gmail.com
Thu Dec 2 23:48:53 UTC 2021


On Thursday, 2 December 2021 at 23:29:17 UTC, Chris Katko wrote:
> there's:
>
> ```d
>   import core.thread;
>   Thread.sleep( dur!("msecs")(10) );
> ```
>
> but what if you want to simply yield all remaining time back to 
> the time scheduler?
>
> Is there a D std.library accessible version of POSIX 
> sched_yield:
>

There's 
https://dlang.org/phobos/core_thread_osthread.html#.Thread.yield

> It seems I can (thanks to the amazing work of D community) 
> simply do:
>
> ```d
> extern(C) int sched_yield(void);  // #include <sched.h>
> ```
>
> however, how does the linker know I need <sched.h> and not some 
> local library, or SDL library, or SDL2.0 library, etc. 
> Shouldn't I be specifying the library somewhere?

Linker doesn't need sched.h. Like H.S.Theoh said, it'll look for 
that symbol in libraries you're linking against. sched_yield is 
in libc, and by default you do link against that.

> ```
> source/app.d(226,16): Error: cannot have parameter of type 
> `void`
> ```
>
> Should that be corrected in the compiler? Shouldn't () and 
> (void) be interchangeable as long as you're not doing void*?

No: https://dlang.org/articles/ctod.html#funcvoid


More information about the Digitalmars-d-learn mailing list