我正在研究Linux下的系统调用读/写操作,然后我发现了这个:
....
loff_t pos = file_pos_read(f.file);
ret = vfs_read(f.file, buf, count, &pos);
file_pos_write(f.file, pos);
fdput(f);
...`
我的问题是:
锁定功能去哪了?我本来想到的是:
....
lock(f.file); // <-- lock file struct
loff_t pos = file_pos_read(f.file);
ret = vfs_read(f.file, buf, count, &pos);
file_pos_write(f.file, pos);
fdput(f);
unlock(f.file); // <-- unlock file struct
...
如果多个线程同时尝试读写,它们可能会在同一个偏移量处进行读写操作?
如果我的理解正确,linux不使用任何锁定机制来保护偏移量,这是否符合POSIX标准?
我确实查看了POSIX规范,并没有找到与此案例有关的内容。