[PATCH v2] nptl: optimize cancelstate and canceltype changing
Alexander Fyodorov
halcy@yandex.ru
Sun Jun 15 16:48:00 GMT 2014
15.06.2014, 19:17, "Rich Felker" <dalias@libc.org>:
> On Sun, Jun 15, 2014 at 03:26:48PM +0400, Alexander Fyodorov wrote:
>> б Changes since v1:
>> б 1) Added a benchtest for pthread_setcanceltype().
>> б 2) Defined atomic_write() macro for old SPARC processors.
>>
>> б atomic_write() macro is needed because on some architectures there
>> б is no hardware support for atomic compare-and-swap, and it is
>> б implemented via spinlock. And writing to variables that are accessed
>> б with such compare-and-swap must be done under the same spinlock to
>> б avoid the race leading to the lost write.
>
> How is this handled for atomic CAS in shared memory? IMO the only way
> to do this with a spinlock is having it be accessible by all
> processes, which would allow any process to deadlock all other
> processes maliciously. The only solution seems to be requiring a
> syscall for CAS, or (preferably) doing something like the ARM kuser
> helper for CAS and refusing to do SMP on such machines.
Good catch, I forgot about shared memory. Currently this macro is only used for threads descriptors which are not allocated in shared memory. So just adding an explanatory comment before atomic_write() should be the way to go I think, until the need arises to use it for shared memory.
More information about the Libc-alpha
mailing list