From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,7b17c7e8b77cdcfe X-Google-Attributes: gidfee84,public From: werme@alingo.zk3.dec.com (Eric Werme) Subject: Re: Alpha UNIX Shared Memory - Need Ideas Date: 1996/04/24 Message-ID: X-Deja-AN: 151244972 references: <4ledut$nql@news1.h1.usa.pipeline.com> organization: Digital Equipment Corporation reply-to: werme@zk3.dec.com newsgroups: comp.unix.osf.osf1 rsurwilo@usa.pipeline.com(Richard A. Surwilo) writes: >However, the application does make heavy use of shared memory with multiple >processes requiring access to shared resources. The biggest potential snag >would seem to be coming up with an efficient method of shared memory >locking under UNIX. I believe the following acquire locks in a few instructions, as long as the locks are available. 173% man pthread_mutex_lock pthread_mutex_lock(3) pthread_mutex_lock(3) NAME pthread_mutex_lock - Locks an unlocked mutex. If the mutex is already locked, the calling thread blocks until the mutex becomes available. LIBRARY DECthreads POSIX 1003.1c Library (libpthread.so) SYNOPSIS #include int pthread_mutex_lock( pthread_mutex_t *mutex); STANDARDS Interfaces documented on this reference page conform to industry standards as follows: IEEE Std 1003.1c-1995, POSIX System Application Program Interface PARAMETERS mutex Mutex to be locked. DESCRIPTION This routine locks a mutex with varying behavior as follows: + If a recursive mutex was specified, the current owner of a mutex can relock the same mutex without blocking. The lock count is incremented for each recursive lock within the thread. + If an error-check mutex was specified and the current owner tries to lock the mutex a second time, the EDEADLK error is reported. If the mutex is locked by another thread, the calling thread waits for the mutex to become available. + If a normal mutex is specified, a deadlock can result if the current owner of a mutex calls this routine in an attempt to lock the mutex a second time. (The deadlock is not detected or reported.) See pthread_mutexattr_settype_np for information about normal, recursive, and error-check mutexes. The thread that has locked a mutex becomes its current owner and remains the owner until the same thread has unlocked it. This routine returns with the mutex in the locked state and with the current thread as the mutex's current owner. RETURN VALUES If an error condition occurs, this routine returns an integer value indi- cating the type of error. Possible return values are as follows: 0 Successful completion. [EINVAL] The value specified for mutex is invalid, or The mutex was created with the protocol attribute set to PTHREAD_PRIO_PROTECT and the calling thread's priority set higher than the mutex's current priority ceiling.) [EDEADLK] A deadlock condition is detected. ERRORS None RELATED INFORMATION Functions: pthread_mutexattr_settype_np(3), pthread_mutex_destroy(3), pthread_mutex_init(3), pthread_mutex_lock(3), pthread_mutex_trylock(3), pthread_mutex_unlock(3) Manuals: Guide to DECthreads and Programmer's Guide 174% man tis_mutex_lock tis_mutex_lock(3) tis_mutex_lock(3) NAME tis_mutex_lock - Locks an unlocked mutex. LIBRARY Standard C Library (libc.so, libc.a) SYNOPSIS #include int tis_mutex_lock( pthread_mutex_t *mutex); STANDARDS None PARAMETERS mutex Mutex to be locked. DESCRIPTION The tis_mutex_lock() function locks a mutex. A deadlock can result if the current owner of a mutex calls this routine in an attempt to lock the mutex a second time. (The deadlock is not detected or reported.) The thread that has locked a mutex becomes its current owner and remains the owner until the same thread has unlocked it. This routine returns with the mutex in the locked state and with the current thread as the mutex's current owner. RETURN VALUES If an error condition occurs, this routine returns an integer value indi- cating the type of error. Possible return values are as follows: 0 Successful completion. [EINVAL] The value specified for mutex is invalid. [EDEADLK] A deadlock condition is detected. ERRORS None RELATED INFORMATION Functions: tis_mutex_destroy(3), tis_mutex_init(3), tis_mutex_lock(3), tis_mutex_trylock(3), tis_mutex_unlock(3) Manuals: Guide to DECthreads and Programmer's Guide -- Eric (Ric) Werme | werme@zk3.dec.com Digital Equipment Corp. | This space intentionally left blank.