/*
* when program is started, a single thread is created, called the initial thread or main thread.
* Additional threads are created by pthread_create.
* So we just need to create two thread in main().
*/
int main(int argc, char** argv)
{
printf("enter main\n");
pthread_t tid1, tid2;
int rc1=0, rc2=0;
rc2 = pthread_create(&tid2, NULL, thread2, NULL);
if(rc2 != 0)
printf("%s: %d\n",__func__, strerror(rc2));
rc1 = pthread_create(&tid1, NULL, thread1, &tid2);
if(rc1 != 0)
printf("%s: %d\n",__func__, strerror(rc1));
printf("leave main\n");
exit(0);
}
/*
* thread1() will be execute by thread1, after pthread_create() * it will set g_Flag = 1;
*/
void* thread1(void* arg)
{
printf("enter thread1\n");
printf("this is thread1, g_Flag: %d, thread id is %u\n",g_Flag, (unsigned int)pthread_self());
g_Flag = 1;
printf("this is thread1, g_Flag: %d, thread id is %u\n",g_Flag, (unsigned int)pthread_self());
printf("leave thread1\n");
pthread_exit(0);
}
/*
* thread2() will be execute by thread2, after pthread_create() * it will set g_Flag = 2;
*/
void* thread2(void* arg)
{
Linux多线程编程手册_IT/计算机_专业资料。Linux多线程编程手册多线程编程指南 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. ...
Linux多线程编程实例解析_IT/计算机_专业资料。haoLinux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件pthread.h,连接时...
linux 下多线程编程 ( C 语言编程)_计算机软件及应用_IT/计算机_专业资料。linux 下多线程编程 ( C 语言编程)linux 下 C 语言多线程编程实例 作者: ...
linux多线程编程_IT/计算机_专业资料。linux 进程线程linux多线程编程 1. 2. Linux下 Linux下线程概述 linux线程 linux线程实现 1、Linux下线程概述进程是系统中...
Linux多线程编程_信息与通信_工程科技_专业资料。自己根据网络资料进行的学习总结第八章 嵌入式 Linux 多线程编程 8.1 线程基本概念 8.1.1 Linux 线程简介 ...
Linux多线程编程讲稿_专业资料。关于Linux的多线程编程介绍博创科技 嵌入互动 第四讲 Linux多线程编程北京博创兴业科技有限公司 北 京 博 创 兴 业 科 技 有...
linux多线程编程相关知识_工学_高等教育_教育专区。linux多线程编程相关知识linux 多线程编程相关知识 进程是系统中程序执行和资源分配的基本单位。每个进程都拥有自己...
关于Linux 多线程编程 Linux 线程分为两类,一是核心级支持线程,在核心级实现线程时,线程的实现依赖于 内核,无论是在用户进程中的线程还是系统进程中的线程,他们...
linux下C语言多线程编程实例_计算机软件及应用_IT/计算机_专业资料。linux多线程编程linux 下 C 语言多线程编程实例 2007 年 11 月 29 日 星期四 10:39 学...
Linux多线程程序设计_IT/计算机_专业资料。Linux多线程程序设计华南理工大学 陈虎 博士 tommychen74@yahoo.com.cn Linux中的线程 ? Linux上的线程和进程都有独立...
热门文档