[fpc-devel] Threading support and C library under Linux/Unix

Michael Schnell mschnell at lumino.de
Wed Jun 23 17:12:29 CEST 2010


On 06/23/2010 04:49 PM, Henry Vermaak wrote:
> On 23/06/10 15:26, Michael Schnell wrote:
>>
>> Other ARMs (including thumb2) uses a loop with result compare. AFAIK
>> this does not work reliably. I am not sure it it's really true that ARM
>
> No, SWP is atomic, so the implementation looks good (at a glance).
>

even if that is true there is a problem:

// lock
  ldr r12, .Lfpc_system_lock
  mov r3, #1
.Lloop:
  swp r3, r3, [r12]
  cmp r3, #0
  bne .Lloop
// do the job

 - thread 1 comes in and sets fpc_system_lock to 1
 - now thread 2 is scheduled and comes in
 - fpc_system_lock is set so it enters a busy spinning

unfortunately we are in a "realtime" system and the priority of thread 2
is set higher than that of thread 1 and thus thread 1 never gets a CPU
cycle as thread 2 is busy and thus we have a dead-lock.

-Michael




More information about the fpc-devel mailing list