[英]Why does pthread_create return an int?
I have seen code for summation of an array using threads. 我看过使用线程求和数组的代码。 In this code a thread is created and an
int
data type is returned: 在此代码中,创建了一个线程并返回了
int
数据类型:
int iret1, iret2;
iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
I knew that a thread is a child of a process and it uses for executing program. 我知道线程是进程的子级,并且用于执行程序。 For the executing program memory is needed, and memory is returned by a
void*
data type. 对于正在执行的程序,需要内存,并且内存由
void*
数据类型返回。
What is the logical reason for returning an int
? 返回
int
的逻辑原因是什么? Can any one explain the actual reason? 有人可以解释实际原因吗?
According to man pthread_create
: 根据
man pthread_create
说法:
Return Value
返回值
On success, pthread_create() returns 0;
成功时,pthread_create()返回0;否则,返回0。 on error, it returns an error number, and the contents of *thread are undefined.
如果出错,则返回错误号,并且* thread的内容未定义。
That value simply indicates whether the thread creation was successful or not. 该值仅表示线程创建是否成功。
It is not a memory allocation call like malloc
, therefore I don't see why you think it should return a pointer. 它不是像
malloc
这样的内存分配调用,因此我不明白为什么您认为它应该返回一个指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.