"is not an lvalue" when passing template function to spawn function
Bienlein
fm2002 at web.de
Thu Nov 9 09:40:47 UTC 2023
On Wednesday, 8 November 2023 at 16:47:02 UTC, Paul Backus wrote:
> On Wednesday, 8 November 2023 at 16:30:49 UTC, Bienlein wrote:
> ...
> The actual problem here is that you can't take the address of a
> template without instantiating it first. To make your example
> work, replace `&addToBiz` with `&addToBiz!int`, like this:
>
> spawn(&addToBiz!int, biz);
Thanks, Paul. This helped a step further. When applying your
change it looks like this:
Biz!int biz = new Biz!int(123);
spawn(&addToBiz!int, biz);
Then I get this error: 'Error: static assert: "Aliases to
mutable thread-local data not allowed."'
For this error I found this in the Internet:
https://stackoverflow.com/questions/14395018/aliases-to-mutable-thread-local-data-not-allowed
But this change, did not help:
spawn(&addToBiz!int, cast(shared) biz);
Then I moved "Biz!int biz = new Biz!int(123);" out of the main
function. Compiler complains about static this. Okay, then the
code outside the main function now looks this way:
class Biz(T) {
private T value;
this(T value) {
this.value = value;
}
}
static void addToBiz(T)(Biz!T biz)
{
// ...
}
Biz!int biz;
static this() {
biz = new Biz!int(123);
}
int main()
{
// ...
}
However, this results in no gain as the compiler now shows the
initial error again: 'Error: static assert: "Aliases to mutable
thread-local data not allowed."'
Everything I tried on my own was also to no avail. If someone
could gould give me a hint again ... ;-)
Thank you.
More information about the Digitalmars-d-learn
mailing list