in reply to Re: •Re: Logical Conundrum
in thread Logical Conundrum

if (unlocked) { lock
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.

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.