程序员的自我修养读书笔记

P8驱动程序:

驱动程序一般指的是设备驱动程序(Device Driver),是一种可以使计算机和设备进行相互通信的特殊程序。相当于硬件的接口,操作系统只有通过这个接口,才能控制硬件设备的工作,假如某设备的驱动程序未能正确安装,便不能正常工作。因此,驱动程序被比作“ 硬件的灵魂”、“硬件的主宰”、“硬件和系统之间的桥梁”等。

我决定就是接口技术哪门课上我们学的,对硬件的中断进行相应,封闭某些中断,对端口改变他的位图的那种程序。

P9 POXIS的API

POSIX:可移植操作系统接口,我看了一下,觉得我们在unix系统环境编程那本书里面学的大部分的接口都是POSIX的,像pthread的接口,人家前面都带‘p’字了,所以肯定是了。

P12的感叹

所以文件系统的工作人员相当只是用磁盘的驱动程序提供接口写一些管理和调度方面的代码?

P16的感叹

因为我们写的代码所用的空间都是虚拟空间,所以我们在我们现在写的代码中对IO端口进行访问是不可能的,至少在这个层次。

P17的感叹

所以说对于现在的一个可执行文件,不运行他的时候他作为一个二进制文件存在磁盘中,运行的时候我们考虑到现在的机子一般是64位的,所以虚拟空间大小至少是以T作为单位的,这个大小比磁盘还大,为了运行这个程序我们使用分页机制,把要用的页拉到内存,如何cpu被别人抢占,那么我们可以把哪些页拉倒磁盘,然后大部分的页由于没有使用到,或者使用过了,既不在内存,也不在磁盘。

P21的感叹

所以说现在的操作系统依旧采用时间片的方式,我一直以为只有分时操作系统才用...

p25的问题

#include<stdio.h>
#include<stdlib.h>
#include <pthread.h>
int i = 0;

void* func(void* p){
  i--;
  pthread_exit(NULL);
}

int main(){
  pthread_t tid;
  pthread_create(&tid,NULL,func,NULL);
  i++;
  printf("%d",i);
  pthread_join(tid,NULL);
}

有大佬解释一下吗,按照书上的说法,正常应该是1,2都有,但我运行了n次了每次结果都是1。推断一下,不知道是不是对的,i++,i--在现在gcc编译器下其实是原子的。

这件事我问了一下chatgpt老师,他给的回答:

In computing, an atomic operation is an indivisible and irreducible operation that appears to occur instantaneously to the rest of the system. In C, some operations are guaranteed to be atomic by the language specification, while others are not.

For example, simple read and write operations on variables of size char, short int and int, as well as pointer assignments, are generally considered to be atomic by the C standard. These operations will appear atomic in a single-threaded program.

However, operations involving larger data types, such as long long, double, or structs, are typically not atomic, even on systems where the underlying hardware provides support for atomic operations on those types.

什么叫震惊我室友一千年,我又问了他IO操作是不是原子的。老师的回答:

Whether IO operations are atomic or not depends on the type of IO operation and the system it is running on. In general, disk I/O operations (reading or writing files to disk) are not atomic because they usually involve multiple steps: opening the file, reading or writing the data, and closing the file.

However, atomicity can be achieved for certain cases of IO operations. For example, some systems provide the functionality of appending data atomically to files using operating system calls like writev. Such operations ensure that writes from all processes or threads are serialized so that no two write() calls interleave.

根据他的解释感觉IO的系统调用应该是原子的,不然都没办法玩下去了。(还能不能愉快的写代码了?)

这个事我还会找老师(真正的老师,不是chatgpt)确认一下的。

p26~30的感叹

我感觉他这几页的意思就是访问全局变量的时候都用互斥量锁一下,然后编译的时候不要开氧气。

p31的感叹

不只是clone我感觉pthread_create也是一对一的。从我们写程序时候内核的繁忙程度就可以看出来。还有感觉一对一模式也没有用户线程数的限制,我们想一个用户线程对应一个内核线程对应一个核,所以我们可以创建很多线程,但是同时上去运行的只有内核个。

好了,第一章就看完了,可能有错误,如果发现我会第一时间回来改的!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值