Linux centOS c语言 多线程编程学习笔记
2016-04-08 22:04
543 查看
开始学习linux下c语言多线程编程,学习一位前辈的博客内容(http://blog.csdn.net/huqinwei987/article/details/7526667#comments),如下:
敲入发现运行有报错
note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(void *)’
看的似懂非懂
直接复制百度一下
找到一个不错的答案
http://stackoverflow.com/questions/28018045/error-in-pointer-multithread-expected-void-void-but-argument-is-of/28018114
看完修改代码如下:
修改处用如图所标,运行成功
/*Hello,world--Single Thread*/ //记得-lpthread链接libpthread.a #include<stdio.h> #include<pthread.h> #define NUM 6 int main(){ void print_msg(void*); pthread_t t1, t2; pthread_create(&t1, NULL, print_msg, (void*)"hello,"); pthread_create(&t2, NULL, print_msg, (void*)"world!\n"); pthread_join(t1, NULL); pthread_join(t2, NULL); } void print_msg(void* m){ char *cp = (char*)m;//有个转换过程 int i; for(i = 0 ; i < NUM ; i++){//隔一秒打印 printf("%s", m); fflush(stdout);//清空 sleep(1);//睡眠一秒 } } /* * 函数原型: * int pthread_create(pthread_t *thread,pthread_attr_t *attr,void *(*func)(void*),void *arg); * 参数: thread 指向pthread_t类型变量的指针 * attr 指向pthread_attr_t类型变量的指针,或者为NULL * func 指向新线程所运行函数的指针 * arg 传递给func的参数 * 返回值 0 成功返回 * errcode 错误 * 我们可以使用函数pthread_join等待某进程结束。 * 函数原型:int pthread_join(pthread_t thread,void ** retval); * 参数: thread 所等待的进程 * retval 指向某存储线程返回值的变量 * 返回值: 0 成功返回 * errorcode 错误 * 以上两个函数都包含在头文件pthread.h中。 */
敲入发现运行有报错
note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(void *)’
看的似懂非懂
直接复制百度一下
找到一个不错的答案
http://stackoverflow.com/questions/28018045/error-in-pointer-multithread-expected-void-void-but-argument-is-of/28018114
看完修改代码如下:
修改处用如图所标,运行成功
相关文章推荐
- Linux没有eth0或者eth0无IP地址解决方法
- Linux中加密和解密技术及CA认证
- Linux内核分析(七)
- 在CentOS 7上构建RAID5、LVM和SAMBA服务器(2)——构建RAID5
- linux下ps命令说明
- (OK) iso—mkisofs—linux—fedora23
- Linux进程退出--exit与return的区别
- 在CentOS 7上构建RAID5、LVM和SAMBA服务器(1)——预备
- 《Linux内核分析》第七周学习总结 可执行程序的装载
- linux:SUID、SGID详解
- linux下简单常用文件查看/处理/排序/统计等命令
- vi 编辑器
- Linux下查看文件内容的命令
- linux下启动和关闭网卡命令及DHCP上网
- 最新资源分享
- Linux上yum安装svn并使用钩子实现自动更新
- Linux下的畅聊系统
- CentOS7 网卡命名
- Linux搭建svn服务器并设置客户端提交自动更新
- 开启linux命令行下英汉词典