- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- void thread( void )
- {
- int i ;
- for ( i = 0; i < 3; ++i )
- {
- printf("this is a pthread\n");
- }
- }
- int main()
- {
- pthread_t id;
- int i , ret;
- ret = pthread_create( &id, NULL, (void *)thread, NULL );
- if ( 0 != ret )
- {
- printf("Create pthread error!\n");
- exit(1);
- }
- for ( i = 0; i < 3; ++i )
- {
- printf("this is the main process. \n");
- pthread_join( id, NULL );
- }
- /*pthread_timedjoin_np();*/
- return 0;
- }
复制代码 同样的一个代码,我用
gcc test.c -lpthread
编译通过,运行也ok
但是使用
g++ test.c -lpthread
却报错为
example1.c: In function ‘int main()’:
example1.c:20: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’
example1.c:20: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
请问原因为何?
还请问下有什么多线程编程的好资料推荐
谢谢 |
|