|
> ANSI C is the de-facto baseline everything has in common,
> using C11+ narrows which platforms you're able to build for.
Sure, but which platforms are you thinking of? I think you're
overestimating the proportion of C codebases that care about targeting
highly exotic hardware platforms. GCC can target all
sorts of ISAs, including embedded platforms.
It can't target, say, the 6502, or PIC, or Z80, but they're small niches.I'm not an embedded software developer though, perhaps there are
more developers using niche C compilers than I realise. > Even if C11 does provide the primitives for correct implementation
> of Peterson's Algorithm, what about the other platforms that don't
> have a C11 compiler - it does them no good.
If portable atomics/synchronisation machinery is not offered by your
C compiler or its libraries, I figure your options are:1. Use platform-specific atomics/synchronisation functionality 2. Leverage compiler-specific guarantees to write platform-specific atomics/synchronisation functionality, if your compiler offers such guarantees 3. Write your atomics/synchronisation functionality in assembly, and call it from C Here's a project that uses all 3 approaches. [0] (It's old-school C++ rather than C, but it's the same in principle.) I'm fairly sure it's not possible to
implement your own portable synchronisation primitives in standard-compliant
C90 code. As I understand it, the C90 standard has nothing at all to
say on concurrency. It's possible that such an attempt might
happen to work, on some given platform, but it would be 'correct by coincidence', rather
than by definition. (Again, unless the particular compiler
guaranteed the necessary properties.) [0] https://github.com/gogglesguy/fox/blob/fe99324/lib/FXAtomic.... |