[M3devel] pthread errors on FreeBSD

Olaf Wagner wagner at elegosoft.com
Thu Jan 10 01:16:03 CET 2008


Quoting Tony Hosking <hosking at cs.purdue.edu>:

> On Jan 8, 2008, at 5:57 PM, Olaf Wagner wrote:
>> This seems to be caused by using the ThreadF interface to suspend
>> other threads. If a mutex is used, the test passes:
>>
>> PROCEDURE Txt (t: TEXT) =
>>  BEGIN
>>    (* ThreadF.SuspendOthers (); *)
>>    LOCK iolock DO
>>      RTIO.PutText (t);
>>    END;
>>    (* ThreadF.ResumeOthers (); *)
>>  END Txt;
>>
>> Apart from the fact that a mutex is the correct thing to use,
>> have you any idea why ThreadF procedures fail? It makes me a bit
>> nervous, as they are used by the garbage collector, aren't they?
>
> ThreadF.SuspendOthers/ResumeOthers are particularly dangerous
> operations that should not be used generally by user-level code,
> especially where multiple threads may simultaneously invoke
> SuspendOthers/ResumeOthers, as in this example.  I suspect also that
> any call to SuspendOthers should only be made when RTOS.LockHeap has
> been called, based on the dependency between LockHeap and SuspendOthers
> in the ThreadPThread implementation.  I could fix this by adding the
> necessary calls to SuspendOthers (since LockHeap is re-entrant), but
> would like you to confirm that the following change "works" (even
> though a lock really is the correct way to go):
>
> PROCEDURE Txt (t: TEXT) =
>   BEGIN
>     RTOS.LockHeap();
>     ThreadF.SuspendOthers ();
>     RTIO.PutText (t);
>     ThreadF.ResumeOthers ();
>     RTOS.UnlockHeap();
>   END Txt;

Though it sounds very convincing, it cannot be completely
right: I've run the test three times with mutual exclusion as suggested,
and it crashed at three different counts, but never completed :-/

Olaf
-- 
Olaf Wagner -- elego Software Solutions GmbH
                Gustav-Meyer-Allee 25 / Gebäude 12, 13355 Berlin, Germany
phone: +49 30 23 45 86 96  mobile: +49 177 2345 869  fax: +49 30 23 45 86 95
    http://www.elegosoft.com | Geschäftsführer: Olaf Wagner | Sitz: Berlin
Handelregister: Amtsgericht Charlottenburg HRB 77719 | USt-IdNr: DE163214194




More information about the M3devel mailing list