[fpc-pascal]two questions plz help

Jonas Maebe jonas at zeus.rug.ac.be
Wed Jan 16 12:36:40 CET 2002

On maandag, januari 14, 2002, at 07:14 , Stefan Ziegenbalg wrote:

> var lock_mem : boolean;
> procedure getmem2(var pt:pointer; size:longint);
> bein
> while lock_mem do
>  delay(1);
> lock_mem:=true;
> getmem(pt,size);
> lock_mem:=false;
> end;
> ;

This isn't MT-safe at all. If two threads are in the "while lock_mem do 
delay(1);" loop, it's possible that when something else sets it to 
false, they both check it before the other one has set it to true. You 
need to do the testing and setting as an atomic operation.


More information about the fpc-pascal mailing list