semaphore

package module
v0.0.0-...-7a1f550 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2018 License: MIT Imports: 5 Imported by: 1

README

go-semaphore

MIT License Build Status Go Report Card Coverage Status

This library provides a wrapper around the C interface for named userspace semaphores on Linux.

sem_overview(7)

POSIX semaphores allow processes and threads to synchronize their actions.

   A  semaphore is an integer whose value is never allowed to fall below zero.  Two
   operations can be performed on semaphores: increment the semaphore value by  one
   (sem_post(3));  and  decrement the semaphore value by one (sem_wait(3)).  If the
   value of a semaphore is currently zero, then a sem_wait(3) operation will  block
   until the value becomes greater than zero.

   POSIX semaphores come in two forms: named semaphores and unnamed semaphores.

 Named semaphores
    A named semaphore is identified by a name of the form /somename; that is,
    a null-terminated string of up to NAME_MAX-4 (i.e., 251) characters  con‐
    sisting  of an initial slash, followed by one or more characters, none of
    which are slashes.  Two processes can operate on the same named semaphore
    by passing the same name to sem_open(3).

    The sem_open(3) function creates a new named semaphore or opens an exist‐
    ing named semaphore.  After the semaphore has  been  opened,  it  can  be
    operated  on  using sem_post(3) and sem_wait(3).  When a process has fin‐
    ished using the semaphore, it can use sem_close(3)  to  close  the  sema‐
    phore.   When  all processes have finished using the semaphore, it can be
    removed from the system using sem_unlink(3).

Documentation

Overview

Package semaphore provides an interface to named userspace semaphores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Semaphore

type Semaphore struct {
	// contains filtered or unexported fields
}

func (*Semaphore) Close

func (s *Semaphore) Close() error

Close closes the named semaphore, allowing any resources that the system has allocated to the calling process for this semaphore to be freed.

func (*Semaphore) GetValue

func (s *Semaphore) GetValue() (int, error)

GetValue returns the current value of the semaphore.

func (*Semaphore) Open

func (s *Semaphore) Open(name string, mode, value uint32) error

Open creates a new POSIX semaphore or opens an existing semaphore. The semaphore is identified by name. The mode argument specifies the permissions to be placed on the new semaphore. The value argument specifies the initial value for the new semaphore. If the named semaphore already exist, mode and value are ignored. For details see sem_overview(7).

func (*Semaphore) Post

func (s *Semaphore) Post() error

Post increments the semaphore.

func (*Semaphore) TimedWait

func (s *Semaphore) TimedWait(d time.Duration) error

TimedWait is the same as Wait(), except that d specifies a limit on the amount of time that the call should block if the decrement cannot be immediately performed.

func (*Semaphore) TryWait

func (s *Semaphore) TryWait() error

TryWait is the same as Wait(), except that if the decrement cannot be immediately performed, then the call returns an error instead of blocking.

func (s *Semaphore) Unlink() error

Unlink removes the named semaphore. The semaphore name is removed immediately. The semaphore is destroyed once all other processes that have the semaphore open close it.

func (*Semaphore) Wait

func (s *Semaphore) Wait() error

Wait decrements the semaphore. If the semaphore's value is greater than zero, then the decrement proceeds, and the function returns, immediately. If the semaphore currently has the value zero, then the call blocks until either it becomes possible to perform the decrement, or a signal interrupts the call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL