Thank you for the complete and clear code sample. I understand now.
Thank you for the complete and clear code sample. I understand now.
Worth noting the guard clause can be used on fields.
type
Thing = object
val {.guard: Lock.}: int
lock: Lock
Run
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]
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
Please, can you write a short example code ??
> 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 ?
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
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.
> Can a change in one object cause a global reallocation of the whole seq ?
No, it cannot.
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
11 matches
Mail list logo