Re: Variable modified by different threads.

2024-12-03 Thread Andy Valencia via Digitalmars-d-learn
On Tuesday, 3 December 2024 at 23:16:00 UTC, Richard (Rikki) Andrew Cattermole wrote: What owned by a thread means is that a pointer is guaranteed to only be accessible by that thread. I.e. the cpu will segfault if you try to access it from another thread. My experience is that aside from thre

Re: Variable modified by different threads.

2024-12-03 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 04/12/2024 11:20 AM, Ali Çehreli wrote: On 12/3/24 9:47 AM, Richard (Rikki) Andrew Cattermole wrote: > On 04/12/2024 6:37 AM, Nick Treleaven wrote: >> |shared| - shared (i.e. accessible) across threads. > > That is already true. That conflicts with my knowledge of data being thread-local

Re: Variable modified by different threads.

2024-12-03 Thread Ali Çehreli via Digitalmars-d-learn
On 12/3/24 9:47 AM, Richard (Rikki) Andrew Cattermole wrote: > On 04/12/2024 6:37 AM, Nick Treleaven wrote: >> |shared| - shared (i.e. accessible) across threads. > > That is already true. That conflicts with my knowledge of data being thread-local by default in D. > You don't need a type quali

Re: Variable modified by different threads.

2024-12-03 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 04/12/2024 6:37 AM, Nick Treleaven wrote: If you use it to indicate anything other than the variable can only be accessed/mutated via atomic operations, you are at best lieing to yourself about the native memory model. All memory is owned by the process, until proven otherwise

Re: Variable modified by different threads.

2024-12-03 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 2 December 2024 at 21:55:55 UTC, Richard (Rikki) Andrew Cattermole wrote: As a type qualifier/storage class, ``shared`` should be called ``atomic``. `shared` is more accurate. Atomic ops are not the only way intended to mutate `shared` data. In fact atomic ops can be slower. If y

Re: Variable modified by different threads.

2024-12-02 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 03/12/2024 4:18 AM, Salih Dincer wrote: On Monday, 2 December 2024 at 08:00:40 UTC, Richard (Rikki) Andrew Cattermole wrote: You don't need both atomics an mutex's, pick one. The compiler wants us to use atomicOp; If you want, take it out of the synchronized(mutex) { } block, it doesn't ma

Re: Variable modified by different threads.

2024-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/24 7:18 AM, Salih Dincer wrote: > On Monday, 2 December 2024 at 08:00:40 UTC, Richard (Rikki) Andrew > Cattermole wrote: >> You don't need both atomics an mutex's, pick one. > > The compiler wants us to use atomicOp; If you want, take it out of the > synchronized(mutex) { } block, it doesn

Re: Variable modified by different threads.

2024-12-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 December 2024 at 08:00:40 UTC, Richard (Rikki) Andrew Cattermole wrote: You don't need both atomics an mutex's, pick one. The compiler wants us to use atomicOp; If you want, take it out of the synchronized(mutex) { } block, it doesn't matter: onlineapp.d(20): Error: read-modify-

Re: Variable modified by different threads.

2024-12-02 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
You don't need both atomics an mutex's, pick one.

Re: Variable modified by different threads.

2024-12-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 December 2024 at 02:29:39 UTC, Ali Çehreli wrote: ... There are several other methods of communicating the request.. I've slightly edited the code that the AI generates. Ali, how is it now, can we say that it is the best method? ```d import core.thread; import core.atomic; impor

Re: Variable modified by different threads.

2024-12-01 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 December 2024 at 02:02:56 UTC, Ritina wrote: How can I implement a program where I have a global integer variable g, and three threads: the first thread increments g by 1, the second thread increments g by 2, and the third thread increments g by 3? Additionally, while these threads

Re: Variable modified by different threads.

2024-12-01 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 2 December 2024 at 02:29:39 UTC, Ali Çehreli wrote: I am not sure whether stopRequested = true is correct even when there is a single writer of that variable. There are several other methods of communicating the request. I chose that one for this example. I notice core.atomic h

Re: Variable modified by different threads.

2024-12-01 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 2 December 2024 at 02:02:56 UTC, Ritina wrote: How can I implement a program where I have a global integer variable g, and three threads: the first thread increments g by 1, the second thread increments g by 2, and the third thread increments g by 3? Additionally, while these threads

Re: Variable modified by different threads.

2024-12-01 Thread Ali Çehreli via Digitalmars-d-learn
On 12/1/24 6:23 PM, Andy Valencia wrote: On Monday, 2 December 2024 at 02:02:56 UTC, Ritina wrote: How can I implement a program where I have a global integer variable g, and three threads: the first thread increments g by 1, the second thread increments g by 2, and the third thread increments

Variable modified by different threads.

2024-12-01 Thread Ritina via Digitalmars-d-learn
How can I implement a program where I have a global integer variable g, and three threads: the first thread increments g by 1, the second thread increments g by 2, and the third thread increments g by 3? Additionally, while these threads are running, I should be able to access the value of g bo