DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

suds_locktry(S)


suds_locktry -- obtain a spin lock without spinning

Syntax

cc . . . -lsuds
#include <sys/semaphore.h>

int suds_locktry(struct suds_lock *lock_addr);

Description

The suds_locktry function is used to obtain a lock if that lock is not already locked. If the lock is already locked then suds_locktry(S) immediately returns without waiting for that lock to become available. When the lock is obtained by suds_locktry, the behavior of the system is equivalent to when suds_lock(S) is used to obtain a lock. Therefore locks should be held for the shortest time possible, system calls should not be made and page faults should be avoided. Canonical lock ordering is necessary with both suds_locktry and the suds_lock function.

Return values

Upon successful completion, the function returns 0 to indicate that the lock was successfully obtained, 1 to indicate that the lock was already in use. Otherwise -1 is returned and errno is set accordingly.

Diagnostics


[EINVAL]
The specified address of the lock is not a valid lock address.

Examples

The following code shows an application using suds_locktry to protect a critical section. When the lock cannot be obtained, the application does not attempt to update the variable counter.
   if (suds_locktry(&lock_all)==1)
      return;
   if (global_condition)
      counter = counter + updatevalue;	
   suds_unlock(&lock_all);

See also

suds_ctrl(ADM), suds_lockinit(S), suds_lock(S), suds_lockstate(S), suds_shmat(S), suds_unlock(S)

Standards conformance

suds_locktry is not part of any currently supported standard; it is an extension of AT&T System V provided by The Santa Cruz Operation, Inc.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003