Skip to main content
8 events
when toggle format what by license comment
Feb 9, 2016 at 23:34 comment added Willy Tarreau It's fun that you mentionned mkdir, it's the one I've been using for ages precisely because it works in scripts, is portable, and is human-debuggable and fixable. It also allows you to store your context in the directory (you often need to keep some temporary data when you have to play with locks).
Dec 19, 2014 at 4:53 comment added msw To support @WarrenYoung's point, using files or directories as poor man's semaphores dates back to when semaphores didn't (portably) exist. If I found myself needing a mutex on the local machine, I'd probably use a POSIX semaphore because that's they were invented for.
Dec 19, 2014 at 0:56 comment added Warren Young There are more flavors of mutex than just pthread mutexes. This one, for a start. Myself, I'd actually reach for a POSIX semaphore instead. But keep in mind, this is not a classroom or a discussion forum. This is a site where you ask a well-focused question and get one (or hopefully more) well-focused answers.
Dec 19, 2014 at 0:46 comment added Chap I'm definitely looking for a Linux C solution. But having looked at this doc, mutexes appear to be used for coordinating between threads, rather than processes.
Dec 19, 2014 at 0:25 comment added Warren Young @Chap: I made that suggestion because a) you mentioned Perl; and b) you're posting this on Unix.SE and not Stack Overflow. Given all that, you should probably be using a semaphore or mutex, and not any of these file-based alternatives.
Dec 18, 2014 at 23:52 comment added Chap @msw pointed me to the solution to the performance problem (see above - I was inadvertently using an NFS-mounted file!). The eventual solution will be coded in C, so Perl and shell won't apply. I'm not sure I fully understand your preference for mkdir, since it doesn't naturally provide queue-until-available behavior for an EXCL lock, and requires spinning. Can you elaborate on the drawbacks to flock?
Dec 18, 2014 at 23:45 history edited Warren Young CC BY-SA 3.0
added links to non-file locking alternatives; added NFS warnings
Dec 18, 2014 at 23:36 history answered Warren Young CC BY-SA 3.0