我有这个 void 函数,带有指向我的线程的指针。当我去编译时,我收到警告:“控制到达非无效函数的结尾”。如果我做
void mythread (void *arg)
和函数我将解决编译器给出的警告,但得到一个新的警告,说:
TA.c:50:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
然后,我把return 0;
“mythread”函数放在末尾,它编译了。但我不确定这是否是正确的做法?
我正在尝试学习 POSIX 系统服务编程。我不知道该怎么办。
建议?我应该尝试输入强制转换参数 3 吗?如何编译我的程序并获得零警告?
#include <limits.h>
#include <pthread.h>
#include <stdio.h>
void *mythread (void *arg)
{
printf("This my Thread Maybe...\n");
}
int main()
{
pthread_t mythread_id;
pthread_attr_t mythread_attr;
size_t stack_size;
int detachstate;
pthread_attr_init (&mythread_attr);
pthread_attr_getdetachstate(&mythread_attr, &detachstate);
if(detachstate == PTHREAD_CREATE_DETACHED)
{
printf("Current Deteached state is Detached\n");
}
else
{
printf("Current Detached state is Joinable\n");
}
pthread_attr_setdetachstate (&mythread_attr, PTHREAD_CREATE_DETACHED);
pthread_attr_getdetachstate (&mythread_attr, &detachstate);
if(detachstate == PTHREAD_CREATE_DETACHED)
{
printf("NEW DETACHED STATE is determined to be deteched\n");
}
else
{
printf("NEW DETACHED STATE is Determine to be Joinable\n");
}
pthread_attr_getstacksize (&mythread_attr, &stack_size);
printf ("Default stack size is %d; minimum is %d\n", stack_size, PTHREAD_STACK_MIN);
pthread_attr_setstacksize (&mythread_attr, PTHREAD_STACK_MIN*2);
pthread_attr_getstacksize (&mythread_attr, &stack_size);
printf("NEW stack size is %d\n", stack_size);
pthread_create (&mythread_id, &mythread_attr, mythread, 0);
return 0;
}