增加 pthread_create 和 pthread_join 函数.
Signed-off-by: rick.chan <chenyang@autoai.com>
This commit is contained in:
parent
398cc5eac4
commit
6fa44da09d
|
@ -62,4 +62,74 @@ The usleep() function returns 0 on success. On error, -1 is returned, with errno
|
|||
|
||||
### 3.1.pthread_create 函数
|
||||
|
||||
**头文件:**
|
||||
|
||||
```cpp
|
||||
#include <pthread.h>
|
||||
```
|
||||
|
||||
**连接库:**
|
||||
|
||||
```Makefile
|
||||
-pthread
|
||||
```
|
||||
|
||||
**函数原型:**
|
||||
|
||||
```cpp
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
|
||||
```
|
||||
|
||||
**说明:**
|
||||
|
||||
The pthread_create() function starts a new thread in the calling process.
|
||||
|
||||
**参数:**
|
||||
|
||||
thread:Before returning, a successful call to pthread_create() stores the ID of the new thread in the buffer pointed to by thread; this identifier is used to refer to the thread in subsequent calls to other pthreads functions.
|
||||
|
||||
attr:The attr argument points to a pthread_attr_t structure whose contents are used at thread creation time to determine attributes for the new thread; this structure is initialized using pthread_attr_init(3) and related functions. If attr is NULL, then the thread is created with default attributes.
|
||||
|
||||
start_routine:The new thread starts execution by invoking start_routine()
|
||||
|
||||
arg:Is passed as the sole argument of start_routine().
|
||||
|
||||
**返回值:**
|
||||
|
||||
On success, pthread_create() returns 0; on error, it returns an error number, and the contents of *thread are undefined.
|
||||
|
||||
### 3.3.pthread_join 函数
|
||||
|
||||
**头文件:**
|
||||
|
||||
```cpp
|
||||
#include <pthread.h>
|
||||
```
|
||||
|
||||
**连接库:**
|
||||
|
||||
```Makefile
|
||||
-pthread
|
||||
```
|
||||
|
||||
**函数原型:**
|
||||
|
||||
```cpp
|
||||
int pthread_join(pthread_t thread, void **retval);
|
||||
```
|
||||
|
||||
**说明:**
|
||||
|
||||
The pthread_join() function waits for the thread specified by thread to terminate. If that thread has already terminated, then pthread_join() returns immediately. The thread specified by thread must be joinable.
|
||||
|
||||
If multiple threads simultaneously try to join with the same thread, the results are undefined. If the thread calling pthread_join() is canceled, then the target thread will remain joinable (i.e., it will not be detached).
|
||||
|
||||
**参数:**
|
||||
|
||||
thread:The pthread_join() function waits for the thread specified by thread to terminate.
|
||||
|
||||
retval:If retval is not NULL, then pthread_join() copies the exit status of the target thread (i.e., the value that the target thread supplied to pthread_exit(3)) into the location pointed to by retval. If the target thread was canceled, then PTHREAD_CANCELED is placed in the location pointed to by retval.
|
||||
|
||||
**返回值:**
|
||||
|
||||
On success, pthread_join() returns 0; on error, it returns an error number.
|
||||
|
|
Loading…
Reference in New Issue