locks on dynamically allocated memory

2023-05-06 Thread archnim
Thank you for the complete and clear code sample. I understand now.

locks on dynamically allocated memory

2023-05-06 Thread archnim
Thank you for the complete and clear code sample. I understand now.

locks on dynamically allocated memory

2023-05-06 Thread ElegantBeef
Worth noting the guard clause can be used on fields. type Thing = object val {.guard: Lock.}: int lock: Lock Run

locks on dynamically allocated memory

2023-05-06 Thread zevv
This is one way to do it. There are probably nicer ways, but this is pretty explicit to show what is happening. import std/locks type Thing = object val: int lock: Lock ThingInfo = object thingPtrs: ptr UncheckedArray[Thing]

locks on dynamically allocated memory

2023-05-06 Thread zevv
No, the guard is not what you are looking for; you will need to put a regular mutex in your object and manually lock/unlock it when you are accessing your data. The .guard informs the Nim compiler about your intentions with regards to locking, it can help you protect your data by warning you th

locks on dynamically allocated memory

2023-05-06 Thread archnim
Please, can you write a short example code ??

locks on dynamically allocated memory

2023-05-06 Thread archnim
> put a lock in these individual elements The only way to attach a lock to a memory space, that I know, is to add a pragma in a variable declaration: var num {.guard: lock}: int Run How can i use them on dynamically allocated items ?

locks on dynamically allocated memory

2023-05-06 Thread zevv
If you make a seq of objects, you should be able to access the individual elements of the seq by their raw pointer address from your threads, and put a lock in these individual elements for fine grained locking of their contents. >From your different threads perspectives, ignore the fact that th

locks on dynamically allocated memory

2023-05-06 Thread archnim
Sorry for insisting. Is there a way to guard a sequence item with a lock ? It would be a waste of time if all my threads had to wait for the same lock (that of the entire seq) to access objects that often don't interact with each other. Thanks in advance.

locks on dynamically allocated memory

2023-05-04 Thread Araq
> Can a change in one object cause a global reallocation of the whole seq ? No, it cannot.

locks on dynamically allocated memory

2023-05-04 Thread archnim
Hello world ! Here is the situation in which I am: I have a certain list of objects, that will evolve during runtime. So I store them in a seq or a table. `let s: seq[MyObj]` Can a change in one object cause a global reallocation of the whole seq ? If it could, then My plan to prevent that is t