DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

suds_locktry(S-osr5)


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-osr5) 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-osr5) 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-osr5), suds_lock(S-osr5), suds_lockstate(S-osr5), suds_shmat(S-osr5), suds_unlock(S-osr5)

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.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005