fslock is dead, long live mutex

Tim Penhey tim.penhey at canonical.com
Tue Jun 21 09:24:47 UTC 2016


Hi folks,

We have finally managed to exorcise the fslock from the codebase. Both 
1.25 and master no longer refer to it at all. We need to remove it from 
the juju/utils package to make sure that people don't accidentally try 
and use it again.

There is a new replacement, the juju/mutex package. To acquire a mutex, 
you create a mutex.Spec structure. You must at least provide a name, 
delay and clock. The delay is how long the code waits between tries to 
acquire the mutex. Named mutexs are shared between processes on the same 
machine. If a process holds the mutex and the process dies, the mutex is 
automatically released.  A spec can also have a timeout value, and/or an 
abort channel.

On linux this is implemented with abstract domain sockets, on windows it 
uses a named semaphore, and on other platforms a flock is used on a 
named temp file.

https://godoc.org/github.com/juju/mutex

Cheers,
Tim



More information about the Juju-dev mailing list