您的位置:首页 > 其它

fseek和fread单独使用线程安全,合在一起需要用线程安全机制

2013-09-01 13:52 801 查看
翻译整理自:http://social.msdn.microsoft.com/Forums/vstudio/en-US/ce7799c2-52e0-4b14-b59b-30357ccb3db2/file-seek-then-read-threadsafety?forum=vcgeneral

1、fseek和fread单独使用线程安全

fseek: "This function locks out other threads during execution and is therefore thread-safe."
http://msdn2.microsoft.com/en-us/library/75yw9bf3(VS.80).aspx

fread: "This function locks out other threads."
http://msdn2.microsoft.com/en-us/library/kt0etdcs(vs.80).aspx

2、fseek和fread联合使用需要加锁或者采用临界区

Another seek can come in between a seek-then-read operation and will need a critical section for it.

It sounds like I'll need to create a windows equivalent of pread:

int pread(handle, location, size, data*)
{
enter critical section
seek
read
leave critical section
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: