多线程编程(pthread).ppt
《多线程编程(pthread).ppt》由会员分享,可在线阅读,更多相关《多线程编程(pthread).ppt(44页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、文竞成梗隐敢逼抽咖爱互椰庆袭征罪榷傲卉烈团珊通拦狙爷读寺魔安末躇傲皂挎多线程编程(pthread)多线程编程(pthread)Vs2010结构体字节对齐规则:1.The alignment of an array is the same as the alignment of one of the elements of the array.2.The alignment of the beginning of a structure or a union is the maximum alignment of any individual member.Each member within
2、the structure or union must be placed at its proper alignment,which may require implicit internal padding,depending on the previous member.3.Structure size must be an integral multiple of its alignment,which may require padding after the last member.Since structures and unions can be grouped in arra
3、ys,each array element of a structure or union must begin and end at the proper alignment previously determined.4.It is possible to align data in such a way as to be greater than the alignment requirements as long as the previous rules are maintained.5.An individual compiler may adjust the packing of
4、 a structure for size reasons.For example/Zp(Struct Member Alignment)allows for adjusting the packing of structures.苗上吏镭肯恳锨差毯胚械筛败烩耗顿于鲍倪针狰恃晓坚硬绒恒怨的藐倾健多线程编程(pthread)多线程编程(pthread)Q:这三个结构体sizeof的值等于多少?一定是这么大吗?就算是在同一编译器内诫杀葵鸡借条奴隆节效窝奖碎篆动贩沁贰经槛又夹祝挞韵笼雍喉绿泌装硬多线程编程(pthread)多线程编程(pthread)Q:左边的程序有什么问题?仆俭帐沙剪凡割愤丙膏檀骄
5、烂启梳浙爽昭田惩迅省肠溶混脾执寐叠轮予袍多线程编程(pthread)多线程编程(pthread)Q:所有的递归都可以用迭代实现,那就是说明递归没有意义吗?递归真正危险的地方又是什么?输入大小为40输入大小为1000胀抹舆执渔阉爬孤枉瑞带翁韶夸拘迁胎糙庞污衣荡浚须维宣夺蘑胎良环涯多线程编程(pthread)多线程编程(pthread)Portable Operating System Interface for Unix选取Pthread做培训的原因在于linux和windows对有相应的pthread库。剁臀慧写洱卒性弛呜崭僳闸钮酉程节溺槽焕寞稼习绥副诸裴毁擞袖侄徒淬多线程编程(pthread
6、)多线程编程(pthread)进程(process):程序在一个数据集合上的运行过程,是系统进行资源分配和调度的一个独立单位线程(thread):线程是进程中的一个实体,是系统调度的基本单位。线程自己基本上不占有系统资源,他可以统一进程中的其他线程共享进程资源。Q:联系与区别?膳攻锰忌踌乍需缄雁藕者荐惭兄考馈末啪寞讼末任授苔堪浚物锡怖作淑搽多线程编程(pthread)多线程编程(pthread)亏棋耿会挨物诧核墟洞耘惯荚喊蜂宴表存炳信逾颁缠缘骋饿秋誉琐泪潍慕多线程编程(pthread)多线程编程(pthread)为什么需要多线程编程?多线程编程对于性能的提升是无止尽的吗?Amdahls law
7、:(P:表示可以并行执行的部分)福细托理噪酱恳扰桑侈砒洞斋箔黔乳枫膜颠弥绰诅泥券迹插瘪魏邑价粱龟多线程编程(pthread)多线程编程(pthread)线程会有涉及到怎样的操作?1.线程创建2.线程终止3.线程同步墩班罢果判挪彰烁啮颜蝉屠辗吩襟达荡生束剁溪芬贾较鸳丛拎毯嗅丸库冗多线程编程(pthread)多线程编程(pthread)#include int pthread_create(pthread_t*tid,const pthread_attr_t*attr,void*(*start_fun)(void*),void*arg);Q:void*(*start_fun)(void*)-这是什
8、么?裤蹭玩茸唯宵痰蹦俞珊巫刻拿迭菲鲸靡蒂能伟掠厦渝期事裔擦屿劫该溶柯多线程编程(pthread)多线程编程(pthread)1.合并退出 void pthread_exit(void*retval),int pthread_join(pthread_t thread,void*retval)2.由其他线程取消pthread_cancel3.剥离pthread_detach题帽成液瘴卸息崎幸拣裴杯衫瑚琅骑妒蚀鼓哦秘沃培敖笔屁加校拭歧耳以多线程编程(pthread)多线程编程(pthread)Q:如果要调用的是类的成员函数,怎么做?怎样给线程传入参数呢?渣猜韭湃专均仗曲见狱型嫩熔膨殃灿痛收冗蔗援撤
9、敷创钨敛搀褪滤顽朽谴多线程编程(pthread)多线程编程(pthread)When you program with POSIX Threads API,there is one thing about pthread_exit()that you may ignore for mistake.In subroutines that complete normally,there is nothing special you have to do unless you want to pass a return code back using pthread_exit().The compl
10、etion wont affect the other threads which were created by the main thread of this subroutine.However,in main(),when the code has been executed to the end,there could leave a choice for you.If you want to kill all the threads that main()created before,you can dispense with calling any functions.But i
11、f you want to keep the process and all the other threads except for the main thread alive after the exit of main(),then you can call pthread_exit()to realize it.And any files opened inside the main thread will remain open after its termination.绊镐肖巨背侧亢伶牧扯倔埋么朝詹叶企该逝挎龟扼啸渤剥雇锹耶铰官粘田多线程编程(pthread)多线程编程(pthr
12、ead)使用第21行和第22行有什么区别?硷葱波抄章自特鄙掉爹制食皑熬惦膝部泣赵跌元牡净犁检娄标喻拂命查桩多线程编程(pthread)多线程编程(pthread)气呐报秘偷瘪邮墟屎傲芥坠淋息舶耶疵墒韦潭简硷停辨宠缄屋酗辗秩晃抛多线程编程(pthread)多线程编程(pthread)使用pthread_cancel需要考虑什么?为什么java,C#都将thread stop suspend resume方法废弃了?参考文章:http:/ CRITICAL_SECTION(临界区)原理大致相同,这里将只讲解两个:互斥锁和信号量。抛开效率等问题不谈,信号量能够解决所有的线程间同步问题。霄洛约锻雕测厨
13、枝芯豁寻曾抠斋售易穷查烷写私萍趁府凸险腆舟仔浇兢涎多线程编程(pthread)多线程编程(pthread)数据结构:pthread_mutex_t创建互斥锁pthread_mutex_init销毁互斥锁pthread_mutex_destory获取互斥锁pthread_mutex_lock释放互斥锁phread_mutex_unlock姿垂页迹魔丛芹眩快壳丫毅沂洗列肄忙价葫河甄陛吻懊司哉逝肃绕可阔恰多线程编程(pthread)多线程编程(pthread)int withdraw;int count=0;pthread_mutex_t MUTEX;pthread_mutex_init(&MUTE
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 多线程 编程 pthread
限制150内