课上内容回忆。

函数签名

  • 两数相加写十种签名

  • 十种脑袋里怎么想都是两三种,实在不能再多了,老师还说六种及格。

  • 我写出来的几种

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 终止自己

相关文章:

  • 2021-04-14
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2021-04-18
  • 2021-07-31
  • 2021-12-05
猜你喜欢
  • 2021-09-21
  • 2022-01-24
  • 2021-08-15
  • 2022-12-23
  • 2022-01-26
  • 2021-09-06
  • 2021-08-09
相关资源
相似解决方案