No, you've got a race condition there. Two processes can both see "unlocked" at the same time, then they both "lock" and they think they've got it.if (unlocked) { lock
That's why you need "atomic test and set". There's really no way around it. The thing that checks for unsettedness needs to also set it if it can, in a way that can't be interrrupted or observed by another process/thread/entity. This usually requires operating-system-level locks.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
In reply to •Re: Re: •Re: Logical Conundrum
by merlyn
in thread Logical Conundrum
by mcogan1966
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |