This is the mail archive of the
mailing list for the libstdc++ project.
gcc 3.2.3 config/os/bits/i386/atomicity.h broken
- From: Joel Sherrill <joel dot sherrill at OARcorp dot com>
- To: libstdc++ at gcc dot gnu dot org, Angelo Fraietta <angelo_f at bigpond dot com>
- Date: Fri, 25 Apr 2003 08:52:10 -0500
- Subject: gcc 3.2.3 config/os/bits/i386/atomicity.h broken
- Organization: OAR Corporation
This area of libstdc++-v3 appears to have had significant
work after the 3.2 branch was cut so I don't know if this
bug is still there.
This file uses instructions which are not available on a
points out that an exception 6 (illegal instruction) will
be generated if lock is used with any instruction other than
the list. xadd is not on this list. Further
points out that BSWAP, CMPXCHG, XADD are 486 and above. So
the code in this file is wrong.
In fact, the config/i386 and config/i486 have the same code.
I only see one way to implement this on an i386 in user space.
Add a spin lock variable (could be static to function) and do
a locked exchange on it. When you get the lock, do a regular
fetch and add. Something like this for pure i386 targets
(written in mail so forgive sloppiness):
static inline _Atomic_word
__exchange_and_add (volatile _Atomic_word *__mem, int __val)
register _Atomic_word __result, __tmp;
static volatile _Atomic_word __lock = 1;
/* obtain the atomic exchange/add lock */
__tmp = 0;
__asm__ __volatile__("xchgl %0,%1"
:"m" (&__lock), "0" (__lock)
} while ( __tmp == 0 );
__result = *__mem;
*__mem += __val;
/* release spin lock */
__lock = 1;
As best I can tell, in gcc 3.3 and later, there is no support
for atomicity.h on the basic i386 at all. Is this right?
If this implementation works, could it be conditionally used
in the x86 atomicity.h for the vanilla i386 and included
in the single file?
Joel Sherrill, Ph.D. Director of Research & Development
joel at OARcorp dot com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985