Acess variable that was set by thread
Steven Schveighoffer
schveiguy at gmail.com
Mon Aug 8 19:33:14 UTC 2022
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 `shared` on a shared variable is not "lying". It
> doesn't matter if C makes the distinction. D does.
If you have all these nice abstractions and careful locking around
accessing the data, but C doesn't, how is this better? Do you feel safer
because of this?
>
>> I'm not saying you should use `__gshared` liberally, or for cases
>> where you are using this only in D. But to say you should *never* use
>> it is incorrect.
>
> If you're clever enough to identify a valid use case for `__gshared` and
> write correct code with it, then you're clever enough to figure out when
> not to listen to me.
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.
> `__gshared` is about as bad as `-boundscheck=off`. They're both glaring
> safety holes. But people want to be propper hackers (TM). And propper
> hackers know how to handle these foot-guns, of course. And then they
> shoot their feet off.
Using `__gshared` to share data with C is as safe as using
`-boundscheck=on` and sending the array into C which has no such
restrictions.
The conclusion here really should just be, don't use C.
-Steve
More information about the Digitalmars-d-learn
mailing list