[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Module suggestion: Atomic operations
From: |
Bruno Haible |
Subject: |
Re: Module suggestion: Atomic operations |
Date: |
Mon, 25 May 2020 09:24:28 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) |
Hi Marc,
> One problem with <stdatomic.h> as given is that atomic values have no
> destructors. Thus, we cannot simply attach locks to them in a pre-C11
> implementation because there is no place to destroy the locks.
Ah...
> Thus, we would have to work with a pool of locks shared by all atomic
> variables. But when to set up the pool?
Pools have the drawback that they add a configuration requirement on the
application: What is the default size of the pool? When to increase the
pool size? By how much? When to shrink the pool? The developer would have
determine good answers to this, but 5 years later or under specific
circumstances the answers may not be good enough. (*)
Therefore, I would avoid pools, unless strictly necessary for performance
reasons. And if you need pools already in the design phase, you've been
doing a mistake.
> A module atomic with a header "atomic.h" could implement an interface
> that has destructors (which are mapped to no-ops when <stdatomic.h> is
> available).
Yes, that's the better way to approach it, then.
Bruno
(*) A very good example is the "pool of registers" design in the SPARC
architecture, with the sliding register windows. In the later SPARC
processors, they have been nothing but a source of complexity.