⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread.3

📁 多线程库
💻 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 NAMEpthread \- An abstract class, to create a threaded program..SH SYNOPSIS.B        #include <thread.h>.sp 2.B         class threaded : public pthread {.sp 0.B           threaded() { };.sp 0.B           ~threaded() { };.sp 1.B           int thread(void *) { // threaded execution happens here };.sp 0.B          }.SH DESCRIPTIONThe.I pthreadclass is a part of the threads C++ library that focuses onsimplifying program threading.By providing an abstract class, like the pthread class, the user ispresented with a simple method of starting a program threaded andis able to select wether the thread is an application by itself ormerely a thread in one..LPThe class provides numerous methods to control the thread, thatis associated with the class.  These methods are focused onsynchronizing the threads execution with the parent thread, andproviding access to local variables, as well as changes the runtimestate of the thread itself..LPThese methods are listed here, with some explanation on how theyfunction..TP 12.B retval()A thread can exeit in two ways, it can do a 'return' from thethread function, or do exit through the 'exit' function call.  Bothof which provide a means to return a value.  To make thelibrary provide similar return means, as the posix threads do,it is possible to do a.I exit(void *)where a pointer to a value is registered as a return value.  Insuch cases, the means in accessing the returned value is throughthis method..TP 12.B joining()This will tell if the thread being executed under the class, willjoin any other process on termination.  If this is the case, theprocess id returned, is an id of a process that is suspended andwill be woken up, when the thread terminates..TP 12.B gerrno()Each thread has its own errno variable, that the threaded programcan set to an error value, with the help of.B error()class method.  It is then possible to read this error value, froma parallel or parent thread with this method..TP 12.B id()Each thread, is started with its own process id.  This is to makecertain that they are separable from the main thread, if everneeded.  This method provides means, to obtain the process id ofthe thread running inside the class..TP 12.B signal()After having received a signal, either a restart or a suspendsignal.  The thread will store it, for others to retreive andexamine its state.  With this method, the user can see if thesignal has been suspended or revived..TP 12.B signal(int)Beyond merely obtaining the signal status, this methd providesthe means of sending a signal to the thread.  It will return thesignal last processed by the thread, which may not be the signalpassed to this function..TP 12.B canceled()This method will report, wether the thread has been canceled withthe.B cancel()method..TP 12.B detached()With this method, parent threads can obtain the status of anychild threads, to see if they are stilled attached (child threads)of it..TP 12.B joinable()When a thread has been detached, for instance... or it is theintention to detach a thread from its parent.  It is not desirablethat it be joined with by other sibling threads.  This methodprovides a means to obtain the status of wether the thread isjoinable by other sibling threads..TP 12.B terminated()If a thread has terminated, this will return a true value tosignify a termination state..TP 12.B exited()If a thread has been exited with the 'exit' call, this willsignify that status..TP 12.B cancelstate()This method will tell the current cancelstate of the thread.  Acancel state can be one of following enumerated items:.IP.I cancel_enable- Cancelations are enabled..sp 0.I cancel_disable- Cancelations are not allowed..TP 12.B canceltype()Threads can be canceled in different ways, it can be terminatedby means of forcing them through the 'exit(-1)' state, uponreceiving a cancel signal.  Or they can be made to jump to apredefined location upon receiving that signal.  Both of whichpredetermine that the cancel state is.I cancel_enableand if not, no cancelation will occur..IP.I cancel_deferred - jump to a user definable location..sp 0.I cancel_asynchronous - exit through the 'exit' method..TP 12.B joining(int)This method is provided to tell the thread to join with a givenprocess upon termination.  The process is assumed to be in slumber,and will be revived when the thread exits.  It is upon the usersresponsibility to ensure that the process being joined with isactually a running process..TP 12.B set(cancel_state)Change the cancel state, to the given parameter..TP 12.B set(cancel_type)Change the cancel type, to the given parameter..TP 12.B set(jumps,sigjump_buf *)Set either of two possible jump locations, the signal jump or thecancel jump, to the jump buffer associated with the methodcall.  Possible values for.I jumpsare:.IP.I cancel_jump - When cancel is received..sp 0.I signal_jump - When restart signal is received.TP 12.B set(booleans,bool)Set any of the boolean values, to the state given.  The booleans parameteris an enumeration code, for the numerous boolean variables thatare located inside the class.  The ones settable are:.IP.I set_canceled   - set the cancel state value..sp 0.I set_terminated - set the terminated state..sp 0.I set_detached - set the detached state..sp 0.I set_exited - set the exited state..TP 12.B cancel()Send the thread, a cancel signal that will cancel it if cancellationis enabled.  If the cancel type is deferred, the cancelation willjump to a location, that has been previously set with set(jumps,...)or exit the thread, if the cancel type is asynchronous..TP 12.B suspend()This is a static method, that will suspend the calling process untila.I restart()signal is received.  Inside this method, cancelations will be ignoredby the thread, except program exits will terminate the process..TP 12.B suspend_with_cancelation()This will suspend the process, until a cancelation has been received,or the process is revived.  Whichever comes first.  The method isstatic, and will work on the process that calls it, and not thethread associated with the class..TP 12.B restart()Send a restart signal to a thread, that has been suspended witheither one of the above methods.  This method is not static, whichmeans that it will restart the thread associated with the class..TP 12.B jump(jumps)Make a jump to either of the registered jump locations, for signalor cancel jumps.  See.I set(jumps,sigjump_buf).TP 12.B exit(void *)The normal posix threads, use a void * as an exit value to returnto parent threads.  This method is provided as an historical meansfor programs that desire to be constructively equivalent to theposix treads.  The value will be accessable with the.I retval()method..TP 12.B exit(int)This way in exiting an application is the one that is usually usedby a program.  It will mark the value passed to the method, as anexit value that will be retrievable with the.I retcode()method..TP 12.B exit()This will effectively be the same as if calling.I exit(0).TP 12.B retcode()See the method.I exit(int)For a way to create a value that is retrievable through this method,but it will simply obtain the return value, registered by a thread.  Itwill only be usable after the thread has terminated..TP 12.B running()This method will tell the caller, whether the scheduler has thethread on running schedule or not.  Its not really usable, sincea zombie process is still on the schedulers list.  Use.I terminated()or.I canceled()to determine if the program is running or not..TP 12.B join()This method will suspend the calling process, until the threadassociated with the call terminates.  When it terminates, it willsend the calling process a restart signal, restoring it to arunning state and returning from this method..LPThe next methods, are provided for shared memory and processscoping.  Process scoping, is when two distinct processes sharememory or variables for synchronisation..TP 12.B set_project(const char *)A program that want's to share its resources must have a way for allother programs to identify its resources.  The way for this tohappen, is to create a name that will identify it... which isupto the user to define.  This method provides a way toset the name of the programs resources..TP 12.B set_permissions(int)When resources are shared, the user can define the permissionsthat will be given to other programs.  A program can allow othersto read it's pages, or to read and write them depending on thenormal unix protection methods for user/gropu/others.  Theparameter passed to this method, is the permissions that shouldbe used when creating shared resources..TP 12.B shalloc(size_t)Allocate a specified amount of shared memory for users use.  Thismemory is taken from the systme is pages, where each page isof.I PAGE_SIZEsize.  The memory returned to the user, is only a fragment of thispage, that is.B size_tin size.  It is recomended that the user keep to the sameprinciples with this method, as normally is done with the.I malloc()system call, as the.I threads libraryprovides for management of the shared memory..TP 12.B shdealloc(void *)Return memory retrieved with the above method, back to theshared memory pool.  This method will collect the shared memorypage back, and upon receiving a whole free page, it willimmediately return it back to the system and destroy itfrom the users address space..LPThe library installs signal handlers for all terminating signals,to ensure that shared memory is destroyed when they aren't neededanymore..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 those who reported their suggestions on how toimprove the threads library.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -