课上内容回忆
课上内容回忆。
函数签名
- 
两数相加写十种签名 
- 
十种脑袋里怎么想都是两三种,实在不能再多了,老师还说六种及格。 
- 
我写出来的几种 
int a, int b;
int sum() {
    return a+b;
}
int sum() {
    int sum = a+b;
    return sum;
}
int sum (int a , int b) {
    return a+b;
}
int sum (int a ,int b) {
    int sum;
    sum=a+b;
    return sum;
}
 
- 老师点拨一下后发现能写出来的貌似不止十个了,例如指针又有几个,结构体有几个,数组有几个......
- 过程抽象最主要的是数量和类型
读者写者问题
- 伪代码(老师所说的PV模型)
- 这是用信号量来判断同步还是互斥,1和0时是互斥,大于1时是同步
Reader{
	While(true){
		P(mutex);
		Readcount+;
		If(Readcount==1)
			P(w);
		V(mutex);
		读
		P(mutex);
		Readcount--;
		If(Readcount==0)
			V(w);
		V(mutex);
	}
}
Writer{
	While(true){
		P(w);
		写
        V(w);
	}
}
多线程
**头文件是#include<pthread.h>
课下用老师上传蓝墨云的代码和PPT又学习了一遍,对线程理解更深入了一些
- 自己在课下又重新编译运行了一遍 和老师结果一样。
- 编译运行使用gcc xxx.c -lpthread 其中的-l是指包含的lib库
- 创建一个新的线程pthread_creat
- 等待某线程终止pthread_join
- 调用 pthread_cancel 终止同一进程中的另一个线程
- 调用 pthread_exit 终止自己
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号