On Monday, 7 January 2013 14:50:21 UTC, Kiste wrote:
Hi!
I'd double the variables, so there's a pair for each value. Plus a flag, which indicates which one of the pair is stable. When updating, I'd write to the "unstable" variable, and toggle the flag afterwards.
This is what I thought originally, and it would work in my specific case. But I'm trying to keep things general (the idea being to submit a new library and save me ever having to think it through again). It doesn't work if, for example, you have two interrupt routines which both decide to write to a variable (one after the other) while it's being read.
I think we probably need two variables, an "interruptible access locked" flag and an "I'm the most recently updated" flag. Then we have a read function and a write procedure, both of which take a flag saying "I'm being called from an interruptible context". A bunch of logic could then choose which instance is safe to access and, hopefully, do it without race conditions.
It was about this point where I thought I'd ask :-)
If nobody else jumps in with the blinding bit of inspiration, I'll have a bash at writing this...
Cheers,
Alun.