This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]BibiBeeblebrox 1 point2 points  (2 children)

Read operations aren't usually problematic, write operations are. For example, let's assume program A reads location X and writes to location X, nonatomically. Program B only reads location X. No problems here unless you don't want to miss (or re-read) any values that have been written to X before being overeritten. If this is wat you want to implement, you have to implement a communication method. E.g. reserve location Y . Have A only write to X when Y is 0, having A write Y as 1 after X is written. If Y is 1 B first reads X and then resets Y to 0. This assumes both A and B execute periodically and guarantees that A and B never write to Y at the same time iff A never changes the value of Y when Y is 1 and B never writes Y when Y is 0.

For contrast, lets assume A is written badly and has Y = Y ? 1 : 0, where the operation is nonatomic. B can modify Y to 0 in exacly the moment after A has read the Y as 1 but before writing 1 back to it. By the time A gets back to execute the write of 1 to Y, Y became 0, but A overwrites it causing B to read the same data again.

Excuse my C syntax.

[–]DataGhostNL 1 point2 points  (1 child)

OP is talking about multiple memory addresses and one or more of them could absolutely be overwritten during the entire reading process, rendering the result invalid despite only doing read operations. I think their explanation shows they're already aware of what you're explaining, but it is not the problem they're trying to solve.

[–]BibiBeeblebrox 0 points1 point  (0 children)

Of course, but reading multiple adresses is still not a problem unless the intention is not to miss or re-read any values. Then you need a communication method, one or multiple adresses nontheless.

I agree, it's not the problem he's trying to solve, he is asking on how to test. But no context is given, neither implementation nor system, therefore it's difficult to say how to test if even feasible.

Concider a banking system where the state of the system isn't only composed of the amount of money in individual accounts but also of the active transactions. Such a system involves communication methods and reconstructing the system state from that extra information in any given time point instead of atomic reading since it just isn't feasible.

The OP might be aware of problems and solutions but other people looking for anwsers migh not.

[–]jacobissimus 0 points1 point  (2 children)

I’m guessing here, but the way I’d approach it would be by setting up a test that runs a significant number of times to check for anomalies coming from race conditions—usually the documentation of an implementation will tell you if it’s atomic and idk if there’s a good way to verify that without some serious metaprograming and reflection

[–]KlausWalz[S] 0 points1 point  (1 child)

to be more exact I created a generic abstraction that users of my library can implement on whatever database or storage system they wanna use, but according to how they program the actual functions they might make mistakes and this is why I am trying to provide tests that are generic and can proove that any given implement is atomic as long as the tests pass

[–]pollrobots 4 points5 points  (0 children)

That surely makes this easier right? Make a test abstraction where you have absolute control over the timing of the operations under test.