NaviServer - programmable web server

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

# ns_sema(n) 4.99.8 naviserver "NaviServer Built-in Commands"

## Name

ns_sema - Operate on semaphore-like objects

## Table Of Contents

## Synopsis

- ns_sema ?arg arg ...?
- ns_sema create ?count?
- ns_sema destroy object
- ns_sema release object ?count?
- ns_sema wait object

## Description

This command provides a mechanism to manipulate semaphore-like objects but are not inter-process capable like true semaphores. They are actually implemented with a mutex and a counter. The legal options (which may be abbreviated) are:

## COMMANDS

ns_sema ?arg arg ...?

ns_sema create ?count?

  Initializes a new semaphore whose count is initialized to zero by default or count otherwise. Returns a handle to the semaphore object.

ns_sema destroy object

  Destroys the semaphore object and frees any resources it was using.

ns_sema release object ?count?

  Releases the semaphore object by incrementing the counter by one by default or by count otherwise. The thread will wake any threads blocking on this semaphore when count is equal to one. This is what is commonly referred to as "semaphore up".

ns_sema wait object

  Waits for a semaphore object to be greater than zero. Will block the thread until this is true. Decrements the counter by one when the counter is greater than zero. This is what is commonly referred to as "semaphore down".

## EXAMPLES

       # need an example here

## See Also

nsd

## Keywords

ns_cond, ns_critsec, ns_event, ns_mutex, ns_thread