📄 mutex.3
字号:
.\" Copyright (c) 1999-2000 Orn E. Hansen <oe.hansen@gamma.telenordia.se>.\".\" Permission is granted to make and distribute verbatim copies of this.\" manual provided the copyright notice and this permission notice are.\" preserved on all copies..\".\" Permission is granted to copy and distribute modified versions of this.\" manual under the conditions for verbatim copying, provided that the.\" entire resulting derived work is distributed under the terms of a.\" permission notice identical to this one.\" .TH THREADS 3 "10 Feb 2000" "Threads 2.0" "Threads C++ Library".SH NAMEmutex \- A class, for process synchronisation..SH SYNOPSIS.B #include <thread.h>.sp 2.B ....sp 0.B mutex mut(attributes::process_private).sp 0.B ....SH DESCRIPTIONThe.I mutexclass is a part of the threads C++ library that focuses onsimplifying program threading.Mutexes provide the means of exclusive access to shared resourcesin a parallel environment. The mutexes created, can be eithercreated with the.I attributes::process_sharedattribute, to make the mutex shared between processes, or with.I attributes::process_privateas shown in the synopsis. That will make the mutex private to thespecified process and its threads.For synchronized access, methods are provided to lock and unlockthe mutex and to test and see if it is locked by another process..LPThese methods are listed here, with some explanation on how theyfunction..TP 12.B lock()This will try and lock the mutex, and return a 0 value to thecalling process if successful. If not successful, the methodwill supsend the calling process, until the mutex is unlockedand then return.The behaviour here, is greatly dependant on the kind of mutexthat has been declared. See.I kind()for further information on the mutex kinds available..TP 12.B trylock()This method will try and lock the mutex, if successful it willreturn with a 0 value to signify success. Else it will returna EBUSY value, if the mutex is locked by another process. Thereare other return values possible, such as EDEADLK wich ispossible if the mutex is a.I mutex_kind::errorcheckand the process trying to lock it is the same as the one whoalready has it locked..TP 12.B unlock()If the mutex is locked, and the process calling the method is theowner of the lock, it will be unlocked and a 0 value returned tosignify a successfull unlock operation. If the mutex is lockedby another process, a EBUSY value will be returned unless themutex is a.I mutex_kind::errorcheckin which casse the returned value will be EPERM to signify thatthere is no permission to unlock it..TP 12.B kind()This method tells the calling process the kind of mutex, it iscommunicating with. The possible values are:.RS 12.TP 12.I fast the mutex can be locked only once..TP 12.I recursive the mutex can be locked several times by its owner..TP 12.I errorcheck same as fast, but does some simple checking..RE.TP 12.B kind(mutex::mutex_kind)Sets the mutex kind to the paremeter passed, and returns thevalue the mutex was set to prior to the call. This enablesa program to set the.I errorcheckkind, and returning it to its original state after use..LPIn a shared environment, it may be desired that mutex variableresources be addressed differently from other resources belongingto a process..TP 12.B project_part(const char *)Give all resources that are of type mutex, a namethat identifies them seperately, yet still branched from themain process. The passed arguement is a branch name, that willidentify all created mutexes. This is a staticmethod, that will apply to all mutexes created afterthe call..LPSuggestions and questions about the threads library should bedirected to.IPkdb-list@brevet.nu.LPOr, to the specified author below. The threads home page is located at:.IPhttp://user.tninet.se/~dpn659b/threads.html.LP.SH AUTHORVersion 2.0Copyright (C) 1999-2000 Orn E. Hansen <oe.hansen@gamma.telenordia.se>..LPThanks to those who reported their suggestions on how toimprove the threads library.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -