CEEOPMT

C library interface: pthread_mutex_trylock()

CEEOPMT conditionally acquires (locks) the mutex referred to by mutex. Conditionally means the call always returns immediately, whether or not the lock is acquired. If the mutex is already locked, the mutex is not acquired. When successful, this function returns with the mutex in the locked state with the calling thread as its owner.

Syntax

void CEEOPMT (mutex, [fc])
CEE_MUTEX   *mutex;
FEED_BACK   *fc;
CEEOPMT
Call this CWI interface as follows:
L     R15,CEECAALEOV-CEECAA(,R12)     CAA address is in R12
L     R15,0296(,R15)
BALR  R14,R15
mutex (input)
The mutex to be locked conditionally.
fc (output/optional)
The feedback code returned by the service. It indicates the degree of success in locking the mutex conditionally. The following message identifiers and associated severities can be returned by the service in the feedback code fc.
Condition Description category Description value
CEE000 Severity 0
Msg_No 0000
Message The service completed successfully.
CEE4S9 Severity 3
Msg_No 5001
Message The service is unavailable unless POSIX(ON) runtime option specified and z/OS UNIX System Services are started.
CEE5I5 Severity 3
Msg_No 5701
Message The pthread_mutex_t object specified by mutex is not valid (not initialized).
CEE5I8 Severity 4
Msg_No 5704
Message Address exception while referencing storage allocated by mutex initialization for pthread_mutex_t object specified by mutex.
CEE5IB Severity 0
Msg_No 5707
Message The pthread_mutex_t object specified by mutex is busy.
CEE5IO Severity 4
Msg_No 5720
Message Thread forced by quiesce.
CEE5IS Severity 0
Msg_No 5724
Message Not enough resource (other than memory).
CEE5K4 Severity 3
Msg_No 5764
Message The mutex specified by mutex was not initialized.
CEE5K6 Severity 3
Msg_No 5766
Message An addressing exception occurred referencing a lock object.
CEE5K7 Severity 4
Msg_No 5767
Message Address exception while referencing system storage allocated by lock object initialization.
CEE5KQ Severity 3
Msg_No 5786
Message The callable service BPX1SLK failed during shared lock processing. The system return code was return_code, the reason code was reason_code, X'00'.
Usage Notes:
  1. If the CEEOPXS service was used to give the mutex the attribute RECURSIVE before the mutex was initialized with the CEEOPMI service, the thread which locked the mutex can relock it with lock service, CEEOPML, or trylock service, CEEOPMT. In other words, trylock returns with success rather than busy feedback code, if the thread already owns a recursive mutex. Only when the mutex is nonrecursive, which is the default attribute for mutexes, does trylock return the busy feedback code if the mutex is already locked.
  2. A recursive mutex must be unlocked as many times as it has been locked and relocked to relinquish ownership.
  3. Only the owning thread (the thread that acquired a mutex) can unlock it.