Re: Semaphores in Delphi



Locke wrote:

I'm trying to implement a simple semaphore to protect critical sections of code with the following procedures.

Question is are these safe, or is it possible that 2 threads could slip through EnterCritical at the same time?

Thanks

procedure EnterCritical;
begin
while semaphore do sleep(30);
semaphore:=true;
end;

procedure ExitCritical;
begin
semaphore:=false;
end;
It's very possible that it can slip through.
if you use the Systems provided API's for criticalsection control,
you'll have a much better chance at handling it.


--
"I'd rather have a bottle in front of me than a frontal lobotomy"

"Daily Thought:

SOME PEOPLE ARE LIKE SLINKIES. NOT REALLY GOOD FOR ANYTHING BUT
THEY BRING A SMILE TO YOUR FACE WHEN PUSHED DOWN THE STAIRS.
http://webpages.charter.net/jamie_5";

.