Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 20:36:34 UTC, Steven Schveighoffer wrote: [...] shared gives you a sense that the language is helping you prevent problems. Again, if C isn't playing ball, this is a lie. The C side is playing ball, by whatever rules the C library chooses. `shared` (with

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 4:04 PM, ag0aep6g wrote: On Monday, 8 August 2022 at 19:33:14 UTC, Steven Schveighoffer wrote: There's nothing clever. If you want to access C globals, you should use `__gshared`, because that's what it is. Using `shared`, isn't going to save you at all. Yes, using `shared` does

Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 19:33:14 UTC, Steven Schveighoffer wrote: There's nothing clever. If you want to access C globals, you should use `__gshared`, because that's what it is. Using `shared`, isn't going to save you at all. Yes, using `shared` does save you. C might not have a `shared`

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 10:54 AM, ag0aep6g wrote: On Monday, 8 August 2022 at 14:29:43 UTC, Steven Schveighoffer wrote: C has no notion of shared, so it's not the right type. Putting `shared` on it is kind of lying, and can lead to trouble. Better to be explicit about what it is. Nonsense. Putting

Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 17:45:03 UTC, bauss wrote: On Monday, 8 August 2022 at 13:55:02 UTC, ag0aep6g wrote: auto x = s.x; ``` Your problem is here and not because it was __gshared. You're copying the value and obviously it can be changed in the meantime, that's common sense.

Re: Acess variable that was set by thread

2022-08-08 Thread kdevel via Digitalmars-d-learn
On Monday, 8 August 2022 at 17:45:03 UTC, bauss wrote: On Monday, 8 August 2022 at 13:55:02 UTC, ag0aep6g wrote: auto x = s.x; [...] Your problem is here and not because it was __gshared. You're copying the value and obviously it can be changed in the meantime, that's common sense.

Re: Acess variable that was set by thread

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 13:55:02 UTC, ag0aep6g wrote: auto x = s.x; ``` Your problem is here and not because it was __gshared. You're copying the value and obviously it can be changed in the meantime, that's common sense. You shouldn't use it like that. You should access s.x

Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 14:29:43 UTC, Steven Schveighoffer wrote: C has no notion of shared, so it's not the right type. Putting `shared` on it is kind of lying, and can lead to trouble. Better to be explicit about what it is. Nonsense. Putting `shared` on a shared variable is not

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 10:12 AM, ag0aep6g wrote: On Monday, 8 August 2022 at 13:31:04 UTC, Steven Schveighoffer wrote: On 8/8/22 6:17 AM, ag0aep6g wrote: [...] Never ever use `__gshared` ever. It's a glaring safety hole. Use `shared` instead. If you are interfacing with C, you need __gshared. But yeah,

Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 13:31:04 UTC, Steven Schveighoffer wrote: On 8/8/22 6:17 AM, ag0aep6g wrote: [...] Never ever use `__gshared` ever. It's a glaring safety hole. Use `shared` instead. If you are interfacing with C, you need __gshared. But yeah, you should use shared in this case.

Re: Acess variable that was set by thread

2022-08-08 Thread frame via Digitalmars-d-learn
On Monday, 8 August 2022 at 10:17:57 UTC, ag0aep6g wrote: By the way, is there some resource that recommends `__gshared` over `shared`? It seems that many newbies reach for `__gshared` first for some reason. Would be also good if the specs would tell more about those "guards": Unlike the

Re: Acess variable that was set by thread

2022-08-08 Thread Ali Çehreli via Digitalmars-d-learn
On 8/8/22 00:14, vc wrote: > i will like to hear thoughts even if it works > for me __gshared would work as well but I would consider std.concurrency first. Just a simple example: import std.stdio; import std.concurrency; import core.thread; struct Result { int value; } struct Done { }

Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 12:45:20 UTC, bauss wrote: On Monday, 8 August 2022 at 10:17:57 UTC, ag0aep6g wrote: Never ever use `__gshared` ever. [...] To sum it up: Single-write/Single-read? __gshared Single-write/Multi-read? __gshared Multi-write/Single-read? shared

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 6:17 AM, ag0aep6g wrote: On Monday, 8 August 2022 at 07:14:33 UTC, vc wrote: it seems change it to working is working ```d  __gshared bool zeus;  ``` but as I'm new in to D, i will like to hear thoughts even if it works for me Never ever use `__gshared` ever. It's a glaring

Re: Acess variable that was set by thread

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 10:17:57 UTC, ag0aep6g wrote: Never ever use `__gshared` ever. I don't agree with this entirely, it just depends on how you use it. In general you should go with shared, but __gshared does have its places. It's only problematic when it can be changed from

Re: Acess variable that was set by thread

2022-08-08 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 8 August 2022 at 07:14:33 UTC, vc wrote: it seems change it to working is working ```d __gshared bool zeus; ``` but as I'm new in to D, i will like to hear thoughts even if it works for me Never ever use `__gshared` ever. It's a glaring safety hole. Use `shared` instead. If

Re: Acess variable that was set by thread

2022-08-08 Thread vc via Digitalmars-d-learn
On Monday, 8 August 2022 at 02:49:06 UTC, Steven Schveighoffer wrote: On 8/7/22 9:36 PM, vc wrote: Hello, i have the following code, the flora contains a boolean zeus in the DerivedThread the boolean zeus was set to true; but when i'm trying to access it outside the thread in main it returns

Re: Acess variable that was set by thread

2022-08-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/7/22 9:36 PM, vc wrote: Hello, i have the following code, the flora contains a boolean zeus in the DerivedThread the boolean zeus was set to true; but when i'm trying to access it outside the thread in main it returns me false; any thoughts ? is zeus declared just as: ```d bool zeus;

Re: Acess variable that was set by thread

2022-08-07 Thread Emanuele Torre via Digitalmars-d-learn
On Monday, 8 August 2022 at 01:36:45 UTC, vc wrote: Hello, i have the following code, the flora contains a boolean zeus in the DerivedThread the boolean zeus was set to true; but when i'm trying to access it outside the thread in main it returns me false; any thoughts ? import flora; class

Acess variable that was set by thread

2022-08-07 Thread vc via Digitalmars-d-learn
Hello, i have the following code, the flora contains a boolean zeus in the DerivedThread the boolean zeus was set to true; but when i'm trying to access it outside the thread in main it returns me false; any thoughts ? import flora; class DerivedThread : Thread { this() {