I will try to explain your questions and/or provide some links on these topics 
(I know nothing about the quality of these links and I know almost nothing 
about the x86-architecture and Iam still a nimnoob). The ARM and various DSP´s 
is my "home". From my point of view, it´s better to understand the basics 
before starting to use the high-level-concurrency-stuff. In java, atomic and 
volatile are two different things ( 
[https://brooker.co.za/blog/2013/01/06/volatile.html](https://brooker.co.za/blog/2013/01/06/volatile.html)
 ).

Atomics in general are used to access the memory atomically so it can not be 
interrupted. If you have, for instance, a 16bit cpu with a 16bit memory-bus, a 
write or read of a 32-bit-word will never be atomic. So with atomics you can do 
lockless-stuff means without synchonisation. Explained here 
[https://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering](https://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering)
 or here 
[https://herbsutter.com/2013/02/11/atomic-weapons-the-c-memory-model-and-modern-hardware](https://herbsutter.com/2013/02/11/atomic-weapons-the-c-memory-model-and-modern-hardware)

With atomics, you can do some kind of "blackmagic", a lockless hashtable for 
instance: 
[http://preshing.com/20130605/the-worlds-simplest-lock-free-hash-table](http://preshing.com/20130605/the-worlds-simplest-lock-free-hash-table)/

The other part is about synchonized access of memory-regions (Mutex and 
Semaphores). Nim offers here the lowlevel stuff Locks, Conditions with wait() 
and signal() (as the cpp api) I posted some code-snippet here 
[https://forum.nim-lang.org/t/3218](https://forum.nim-lang.org/t/3218) where 
you can experiment with. Also you may take a look into some nim-modules 
(threadpool for instance)

Nim offers also high-level concurrency stuff (Threadpool (spawn and ^), Guards 
and Channels) for safer access but beware of the thread-local gc. Just pass 
pointers between threads so the gc is not "playing" with it.

I hope I could help you a little bit.

Reply via email to