thrd_join 的 return 值与其 res 参数的区别?
Difference between the return value of thrd_join and its res parameter?
我很难理解thrd_join的用法。它的声明是这样的:
int thrd_join( thrd_t thr, int *res );
该部分内容如下:
If res is not a null pointer, the result code of the thread is put to the location pointed to by res
所以我认为变量res包含要加入线程的return代码。 thrd_join() 的 return 值是干什么用的?那是表示连接成功的代码,我可以认真对待 res 的内容吗?
我说得对吗?
线程是started with a function of thrd_start_t
which is typedef for int(*)(void*)
(cf. here), i.e. it takes a void *
, and returns an int
. The return value of this function is stored to the location pointed to by res
. The return code of the call tothrd_join
本身就是它的return值。
该函数就像 C 中的许多函数,其中函数 return 是一个 "error code" 表示错误或成功,并且该函数有一个 out 参数来保存实际输出。
在某些情况下,您可以忽略这些错误代码,例如 printf
returns int
,但我们大多不检查其 return 类型。
当错误案例很有可能出现时,最好检查错误。
请注意,在 java
或 C#
等语言中,函数 return 是实际输出,而 Exceptions
是表示可能错误的方式。
我很难理解thrd_join的用法。它的声明是这样的:
int thrd_join( thrd_t thr, int *res );
该部分内容如下:
If res is not a null pointer, the result code of the thread is put to the location pointed to by res
所以我认为变量res包含要加入线程的return代码。 thrd_join() 的 return 值是干什么用的?那是表示连接成功的代码,我可以认真对待 res 的内容吗?
我说得对吗?
线程是started with a function of thrd_start_t
which is typedef for int(*)(void*)
(cf. here), i.e. it takes a void *
, and returns an int
. The return value of this function is stored to the location pointed to by res
. The return code of the call tothrd_join
本身就是它的return值。
该函数就像 C 中的许多函数,其中函数 return 是一个 "error code" 表示错误或成功,并且该函数有一个 out 参数来保存实际输出。
在某些情况下,您可以忽略这些错误代码,例如 printf
returns int
,但我们大多不检查其 return 类型。
当错误案例很有可能出现时,最好检查错误。
请注意,在 java
或 C#
等语言中,函数 return 是实际输出,而 Exceptions
是表示可能错误的方式。