NaviServer - programmable web server
4.99  5.0

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

ns_rwlock(n) 4.99.30 naviserver "NaviServer Built-in Commands"

Name

ns_rwlock - Create, destroy, and manipulate read/write locks

Table Of Contents

Synopsis

Description

Create, destroy, and manipulate read/write locks.

COMMANDS

ns_rwlock create

Initialize a read/write lock and returns an ID for it.

ns_rwlock destroy rwlockid

Free the resources associated with the specified read/write lock. The rwlockid argument is the read/write lock ID returned by ns_rwlock create when the lock was created.

ns_rwlock readlock rwlockid

Acquire a read lock. Any number of read locks can be pending. If there's a write lock active, the read lock acquisition blocks until the write lock is released.

ns_rwlock readunlock rwlockid

Release a read lock.

ns_rwlock writelock rwlockid

Acquire a write lock. Only one write lock can be in effect. If there are pending read locks active, the write lock acquisition blocks until all of the read locks drain. If a subsequent read lock acquisition attempt is made, the write lock has priority.

ns_rwlock writeunlock rwlockid

Release a write lock.

EXAMPLES

 Put some examples here to illustrate command usage.

NOTES

About Read/Write Locks

Read/write locks are a serialization mechanism for using data structures where multiple reads can happen simultaneously, but where writes must happen singly. For example, suppose you have a hash table that is heavily used but doesn't change very often. You'd like to have multiple threads be able to read from the table without blocking on each other, but when you need to update the table, you can do so safely without having to worry about other threads reading incorrect data.

The principal feature of read/write locks is the mechanism of which locks have priority and which locks must wait. Any number of read locks can be pending. If there's a write lock active, the read lock acquisition blocks until the write lock is released. Also, only one write lock can be in effect. If there are pending read locks active, the write lock acquisition blocks until all of the read locks drain. If a subsequent read lock acquisition attempt is made while a write lock is waiting to acquire, the write lock has priority.

See Also

nsd

Keywords

NaviServer, server built-in