From 6fa44da09d08c8271266a854a49f1ad73a508010 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Mon, 12 Apr 2021 09:25:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20pthread=5Fcreate=20?= =?UTF-8?q?=E5=92=8C=20pthread=5Fjoin=20=E5=87=BD=E6=95=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Linux/User/API/Linux_常用_C_API.md | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Software/Development/OperatingSystem/Linux/User/API/Linux_常用_C_API.md b/Software/Development/OperatingSystem/Linux/User/API/Linux_常用_C_API.md index 6fe33ab..f48f903 100644 --- a/Software/Development/OperatingSystem/Linux/User/API/Linux_常用_C_API.md +++ b/Software/Development/OperatingSystem/Linux/User/API/Linux_常用_C_API.md @@ -62,4 +62,74 @@ The usleep() function returns 0 on success. On error, -1 is returned, with errno ### 3.1.pthread_create 函数 +**头文件:** + +```cpp +#include +``` + +**连接库:** + +```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 +``` + +**连接库:** + +```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.