I suggested to Bryan Albright,
| :0
| * conditions
| {
| LOCKFILE=file.lock # regional lockfile inside braces -- trust me
|
| INCLUDERC=file # assigns $COUNT without a cat or a write
|
| :0
| * $ ${COUNT:-0}^0
| * 1^0
| { NEWCOUNT = $= }
|
| :0chi
| | echo "COUNT=$NEWCOUNT" > file
|
| LOCKFILE # release regional lock
| }
Come to think of it, you could do the same thing in a clone:
:0c:file.lock
* conditions
{
INCLUDERC=file # assigns $COUNT without a cat or a write
:0
* $ ${COUNT:-0}^0
* 1^0
{ NEWCOUNT = $= }
:0hi
| echo "COUNT=$NEWCOUNT" > file
HOST # in case of fall-through (highly unlikely with i and no w)
}
That should fairly safely serialize the updates to the counter.