Skip to content

Nondeterminism when incrementing a variable concurrently #888

@andychu

Description

@andychu

I did a little more testing based on the lobsters discussion: https://lobste.rs/s/hj3np3/mvdan_sh_posix_shell_go

If I run f | f with the function f below (using the elvish-HEAD binary), sometimes the variable is incremented by one, and sometimes it's incremented by 2.

My suspicion is that this is a race condition. If that's the case I think it would be undefined behavior in Go, and would be flagged by Go's race detector (though I didn't try).

~/install> fn f { echo ---;  a = (+ $a 1) }


~/install> echo $a
22
~/install> 
~/install> f|f
---
~/install> echo $a
23
~/install> f|f
---
~/install> echo $a
25
~/install> f|f
---
~/install> echo $a
26
~/install> f|f
---
~/install> echo $a
27
~/install> f|f
---
~/install> echo $a
29

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions