www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing delegate indirectly to createLowLevelThread doesn't work

reply Tejas <notrealemail gmail.com> writes:
```d
import std;
import core.thread.osthread;

void delegate() f;
void main()
{
     void func(){}
     f = &func;
     createLowLevelThread(&func, 2<<30);//works
     createLowLevelThread(f, 2<<30);// doesn't  work!!
}

```

Can someone help?
Jul 26 2021
parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 26 July 2021 at 15:29:26 UTC, Tejas wrote:
 ```d
 import std;
 import core.thread.osthread;

 void delegate() f;
 void main()
 {
     void func(){}
     f = &func;
     createLowLevelThread(&func, 2<<30);//works
     createLowLevelThread(f, 2<<30);// doesn't  work!!
 }

 ```

 Can someone help?
The delegate must be `nothrow`: ```d void delegate() nothrow f; ```
Jul 26 2021
parent reply Tejas <notrealemail gmail.com> writes:
On Monday, 26 July 2021 at 15:42:44 UTC, Paul Backus wrote:
 On Monday, 26 July 2021 at 15:29:26 UTC, Tejas wrote:
 ```d
 import std;
 import core.thread.osthread;

 void delegate() f;
 void main()
 {
     void func(){}
     f = &func;
     createLowLevelThread(&func, 2<<30);//works
     createLowLevelThread(f, 2<<30);// doesn't  work!!
 }

 ```

 Can someone help?
The delegate must be `nothrow`: ```d void delegate() nothrow f; ```
Doesn't seem to matter. I tried that beforehand. And even if it did why does passing it directly work without explicitly qualifying it as nothrow then?
Jul 26 2021
next sibling parent Tejas <notrealemail gmail.com> writes:
On Monday, 26 July 2021 at 16:46:40 UTC, Tejas wrote:
 On Monday, 26 July 2021 at 15:42:44 UTC, Paul Backus wrote:
 On Monday, 26 July 2021 at 15:29:26 UTC, Tejas wrote:
 ```d
 import std;
 import core.thread.osthread;

 void delegate() f;
 void main()
 {
     void func(){}
     f = &func;
     createLowLevelThread(&func, 2<<30);//works
     createLowLevelThread(f, 2<<30);// doesn't  work!!
 }

 ```

 Can someone help?
The delegate must be `nothrow`: ```d void delegate() nothrow f; ```
Doesn't seem to matter. I tried that beforehand. And even if it did why does passing it directly work without explicitly qualifying it as nothrow then?
Sorry, it seems to work now. But why didn't it fail when I didn't qualify ```func``` as nothrow?
Jul 26 2021
prev sibling parent reply JG <JG somewhere.com> writes:
On Monday, 26 July 2021 at 16:46:40 UTC, Tejas wrote:
 On Monday, 26 July 2021 at 15:42:44 UTC, Paul Backus wrote:
 On Monday, 26 July 2021 at 15:29:26 UTC, Tejas wrote:
 ```d
 import std;
 import core.thread.osthread;

 void delegate() f;
 void main()
 {
     void func(){}
     f = &func;
     createLowLevelThread(&func, 2<<30);//works
     createLowLevelThread(f, 2<<30);// doesn't  work!!
 }

 ```

 Can someone help?
The delegate must be `nothrow`: ```d void delegate() nothrow f; ```
Doesn't seem to matter. I tried that beforehand. And even if it did why does passing it directly work without explicitly qualifying it as nothrow then?
It does work for me. To me running the following explains why: ```d import std; import core.thread.osthread; void delegate() f; void main() { void func(){} f = &func; pragma(msg,typeof(&func)); pragma(msg,typeof(f)); createLowLevelThread(&func, 2<<30);//works //createLowLevelThread(f, 2<<30);// doesn't work!! } ```
Jul 26 2021
parent reply Tejas <notrealemail gmail.com> writes:
On Monday, 26 July 2021 at 17:01:13 UTC, JG wrote:
 On Monday, 26 July 2021 at 16:46:40 UTC, Tejas wrote:
 On Monday, 26 July 2021 at 15:42:44 UTC, Paul Backus wrote:
 On Monday, 26 July 2021 at 15:29:26 UTC, Tejas wrote:
 [...]
The delegate must be `nothrow`: ```d void delegate() nothrow f; ```
Doesn't seem to matter. I tried that beforehand. And even if it did why does passing it directly work without explicitly qualifying it as nothrow then?
It does work for me. To me running the following explains why: ```d import std; import core.thread.osthread; void delegate() f; void main() { void func(){} f = &func; pragma(msg,typeof(&func)); pragma(msg,typeof(f)); createLowLevelThread(&func, 2<<30);//works //createLowLevelThread(f, 2<<30);// doesn't work!! } ```
Yeah after reading the error diagnostics carefully I realized that the compiler is inferring many attributes when passing ```func``` directly but not when passing via delegate
Jul 26 2021
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Monday, 26 July 2021 at 17:14:45 UTC, Tejas wrote:
 Yeah after reading the error diagnostics carefully I realized 
 that the compiler is inferring many attributes when passing 
 ```func``` directly but not when passing via delegate
Well, technically, it is inferred there too, but since you specified `void delegate()` it implicitly casts to that and drops the detail. Similar to the difference between like Object o = new MyClass; // now o is still Object since the class implicitly casted and thus drops the extensions in the child class and auto c = new MyClass; // no conversion requested there, c has the full type of MyClass
Jul 26 2021
parent Tejas <notrealemail gmail.com> writes:
On Monday, 26 July 2021 at 17:21:04 UTC, Adam D Ruppe wrote:
 On Monday, 26 July 2021 at 17:14:45 UTC, Tejas wrote:
 Yeah after reading the error diagnostics carefully I realized 
 that the compiler is inferring many attributes when passing 
 ```func``` directly but not when passing via delegate
Well, technically, it is inferred there too, but since you specified `void delegate()` it implicitly casts to that and drops the detail. Similar to the difference between like Object o = new MyClass; // now o is still Object since the class implicitly casted and thus drops the extensions in the child class and auto c = new MyClass; // no conversion requested there, c has the full type of MyClass
Thank you very much for further explaining this :D
Jul 26 2021