why cannot spawn function defined in unittest block {}?

mw mingwu at gmail.com
Sat Jun 20 17:41:47 UTC 2020


put the code from:

https://tour.dlang.org/tour/en/multithreading/synchronization-sharing

in file, and put unittest block from safePrint() to main()

as here:

https://github.com/mingwugmail/dlang_tour/blob/master/spawn_in_unittest.d#L33

-----------------
$ dmd -unittest spawn_in_unittest.d
spawn_in_unittest.d(87): Error: template std.concurrency.spawn 
cannot deduce function from argument types !()(void 
delegate(shared(SafeQueue!int) queue, shared(int)* queueCounter) 
@system, shared(SafeQueue!int), shared(int)*), candidates are:
/usr/include/dmd/phobos/std/concurrency.d(460):        spawn(F, 
T...)(F fn, T args)
   with F = void delegate(shared(SafeQueue!int), shared(int)*) 
@system,
        T = (shared(SafeQueue!int), shared(int)*)
   must satisfy the following constraint:
        isSpawnable!(F, T)
spawn_in_unittest.d(88): Error: template std.concurrency.spawn 
cannot deduce function from argument types !()(void delegate(Tid 
owner, shared(SafeQueue!int) queue, shared(int)* queueCounter) 
@system, Tid, shared(SafeQueue!int), shared(int)*), candidates 
are:
/usr/include/dmd/phobos/std/concurrency.d(460):        spawn(F, 
T...)(F fn, T args)
   with F = void delegate(Tid, shared(SafeQueue!int), 
shared(int)*) @system,
        T = (Tid, shared(SafeQueue!int), shared(int)*)
   must satisfy the following constraint:
        isSpawnable!(F, T)
-----------------

spawn in unitest: why this compiler error? confusing message




More information about the Digitalmars-d-learn mailing list