On 06/24/2010 11:05 AM, Henry Vermaak wrote: > > /* Atomic compare and exchange. These sequences are not actually atomic; > there is a race if *MEM != OLDVAL and we are preempted between the two > swaps. However, they are very close to atomic, and are the best that a > pre-ARMv6 implementation can do without operating system support. > LinuxThreads has been using these sequences for many years. */ > >
:) :) :) "Very close to atomic" is funny, regarding that the (obviously rare) case of non-atomic behavior will cause a system crash. > The linux specific code is here.. > I suppose this uses the said "atomic region" method: - Userspace (without doing a change to system mode) calls a function provided by the system in a dedicated place (in user-space, write protected and common for all processes) - if no interrupt happens everything is fine - the interrupt code in the Kernel detects if the interrupted user space function was preempted in the middle of such a function (i.e. PC in the atomic area) - if such a condition is detected the kernel correctly completes the function for the user space process and adjusts the user space PC before returning to user space into this or another procedure / thread. With such systems the C library (i.e. macros in .h files) for "atomic_..."-functions is provided as a call to the appropriate "atomic region" function. Of course this can be done directly in the RTL, as the addresses of the "atomic_..."-functions is supposed to be stable. -Michael _______________________________________________ fpc-devel maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-devel
