Data Repository Locking

I read a value from the Data Repository, increment in Script, then Push the incremented value back into the Repository. Is this thread-safe? I’m worried about concurrency and a second instance reading the value before the first process has finished storing the incremented value.

How is locking implemented? Or is there a “one-step” operation to read/update a value from the Repository?

The Data Repository was designed from the get-go for multithreaded access. However, that does not guarantee that all threads will read the updated value: if the reading thread accesses the value 1ms before the writing thread, then obviously it will read the previous value.

But as soon as the writing thread has updated the value, then any subsequent read operation will retrieve the updated value.

How could I engineer this process to be completely safe? As a feature request, I believe a “lock / unlock” plugin would be helpful.

It is completely safe. A separate lock/unlock plugin would not add anything to it: although the writing process locks the value while it updates it (which it currently does), it still can’t prevent the reading process from reading the value 1ms before the lock occurs.

And if the reading process locks the value, then obviously the writing process can’t update it.

I’m afraid that if you are counting on record locking to engineer multi-threaded access to certain values, your design is flawed. The only way to ensure all values are always updated simultaneously for all processes would be to funnel all read and write requests through a single process… which means you are no longer multi-threaded.

You’d have to give me an actual example of what you’re trying to achieve (or trying to prevent).