Documentation
¶
Index ¶
- type Mutex
- func (m *Mutex) Lock(ctx context.Context) error
- func (m *Mutex) RLock(ctx context.Context) error
- func (m *Mutex) Read(b []byte) (int, error)
- func (m *Mutex) ReadAt(b []byte, off int64) (int, error)
- func (m *Mutex) Seek(offset int64, whence int) (int64, error)
- func (m *Mutex) Unlock(ctx context.Context) error
- func (m *Mutex) Write(b []byte) (int, error)
- func (m *Mutex) WriteAt(b []byte, off int64) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex is a file-based mutex intended to facilitate cross-process synchronization. Locks acquired by Mutex are advisory, so all participating processes must use advisory lock features in order to co-operate. Locks acquired by Mutex are not inherited by child processes and are automatically released when the process exits.
It is not intended for in-process synchronization, and should not be shared between goroutines without being appropriately guarded by a sync.Mutex.
Upgrading a read-lock to a write lock, or vice-versa, is not guaranteed to happen atomically (on Windows, it is guaranteed not to be atomic).
The io.ReadWriteSeeker, io.ReaderAt, and io.WriterAt interfaces are implemented by *Mutex and are safe to be used once any lock as been acquired (as the result of Mutex.RLock or Mutex.Lock), and until the mutex has been released (Mutex.Unlock). Attempting to use these interfaces without a lock being held results in fs.ErrClosed. On UNIX platforms, it is generally OK to use different file descriptors to access the locked file, as the lock is held by the process, not the individual file descriptor. On Windows however, it is important to use the Mutex to perform IO operations, in particular when a write lock is used, as the lock is tied to the specific file descriptor.
func (*Mutex) Lock ¶
Lock attempts to lock the file for reading & writing. It blocks until the lock is acquired, or an error happens. If the file is already locked for reading, it will upgrade the lock to a read-write lock.
func (*Mutex) RLock ¶
RLock attempts to lock the file for reading. It blocks until the lock is acquired, or an error happens. If the file is already locked for writing, it will downgrade the lock to a read-only lock.