"is not an lvalue" when passing template function to spawn function

Bienlein fm2002 at web.de
Thu Nov 9 10:14:46 UTC 2023


On Thursday, 9 November 2023 at 09:40:47 UTC, Bienlein wrote:
> 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.

If I supply a callback function with the parameter not being an 
instance from a parameterized class I get the same error. The 
problem seems to be that the parameter of the callback function 
takes on object as a parameter and not a built-in type like int 
or String.

The samples on how to use the spawn function on dlang.org does 
not contain a sample on how to get things to work with a objecgt 
being supllied as parameter to the callback function


More information about the Digitalmars-d-learn mailing list