I wanted to quickly implement some sort of locking in perl program on linux, which would be shareable between different processes.
So I used mkdir
as an atomic operation, which returns 1
if the directory doesn't exist and 0
if it does. I remove the directory right after the critical section.
Now, it was pointed to me that it's not a good practice in general (independently on the language). I think it's quite OK, but I would like to ask your opinion.
edit: to show an example, my code looked something like this:
while (!mkdir "lock_dir") {wait some time}
critical section
rmdir "lock_dir"