1 线程与进程的对比

  这里有一个笔记详细的阐述

  http://blog.csdn.net/laviolette/article/details/51506953

2 创建线程函数

  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg);

  参数意义:

    typedef unsigned long int pthread_t

    (1)pthread_t *thread:存储线程ID 唯一

    (2)const pthread_attr_t *attr:线程属性 设置与栈相关的属性 通常为NULL

    (3)void *(*start_routine) (void *):函数指针 指定运行哪个函数代码

    (4)void *arg:运行函数的参数地址 通常给自定义函数传入参数

例子:创建新线程 并使用结构体传递多个参数 注意编译的时候就加上-lpthread

 #include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> struct student
{
int age;
char* name;
}; void *print(struct student *str)
{
printf("the age is %d\n",str->age);
printf("the name is %s\n",str->name);
} int main()
{
struct student stu;
pthread_t thread_id;
stu.age = ;
stu.name = "gogogo";
pthread_create(&thread_id,NULL,(void*)*print,&stu);//创建线程
printf("the new thread id is %u\n",thread_id);
pthread_join(thread_id,NULL);//在主线程等待子线程结束
return ;
}

补充:int pthread_join(pthread_t thread, void **retval);线程等待函数

    

最新文章

  1. 图表插件Charts.js的使用
  2. hdu3530 单调队列
  3. Coursera台大机器学习课程笔记5 -- Theory of Generalization
  4. js学习心得之思维逻辑与对象上下文环境(一)
  5. OAF_开发系列10_实现OAF动态LOV设定
  6. Html - 仿QQ空间右下角工具浮动块
  7. thinkphp框架dump友好调试输出函数
  8. visualSVN server库迁移(转)
  9. Windows文件监视器 1.0 绿色版
  10. 泛型集合转化为DataTable
  11. Linux学习笔记一
  12. java中Arrays的用法
  13. 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求
  14. python3 读入一个jpg格式的图片,并转换长宽像素个数,然后进行绘制
  15. 关于angularjs中路由页面强制更新的问题
  16. Sweetkang 的机器学习实验室 (1)
  17. centos7.5安装opendesktop
  18. IO流入门-概述
  19. OC语言自定义打印
  20. ICCV 2017 Best Paper Awards

热门文章

  1. 【Todo】Java Callable和Future学习
  2. $.ajax里一个中文全角逗号引发的惨案
  3. 生活娱乐 Wifi机器人的制作流程
  4. centos或者ubuntu设置ssh免密码登陆
  5. 【转载】C#中回滚TransactionScope的使用方法和原理
  6. 使用 Docker 在 Linux 上托管 ASP.NET Core 应用程序
  7. 怎样更改Linux中默认的openjdk为自己安装的JDK
  8. Java Unit Testing - JUnit &amp; TestNG
  9. MapReduce算法形式四:mapjoin
  10. 一个基本的spring+mybatis所需要的包