我正在研究如何在
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); //
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); //
...
如果多个线程同时尝试读/写,它们可以在相同的偏移量下读/写?
如果我的理解是正确的,那个linux不使用任何锁定机制来保护偏移量,这个POSIX是否兼容?
我确实看过POSIX规范,但没有发现这个案例.