[fpc-devel] Mutex!

Amir Avani aavani at iust.ac.ir
Sun Nov 5 17:12:24 CET 2006


Thanks Michael, you are right!
I want to know how should I use Criticalsections to make my program to
print only one "here".
 
Michael Müller wrote:
>
> Am 05.11.2006 um 12:14 schrieb Colin Western:
>
>> Amir Aavani wrote:
>>>  InitCriticalSection (cs);
>>>  while true do
>>>  begin
>>>    EnterCriticalsection (cs);
>>>    WriteLn ('Here!');
>>>  end;
>>>    LeaveCriticalsection (cs);
>>
>> Each Enter.. must be matched by a Leave..., and you don't need the
loop. The standard way of doing this is:
>
> I'm sure that this is clear for Amir. But in his example he (and me too)
expects that the loop should stop at the second time it calls
EnterCriticalsection() because the old critical section wasn't left.
>
>> EnterCriticalsection (cs);
>> try
>>   WriteLn ('Here!');
>> finally
>>   LeaveCriticalsection (cs);
>> end;
>
> But this is not an example to show how a critical section stops another one.
>
> Regards
>
> Michael
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel






More information about the fpc-devel mailing list