关于线程同步的问题。
我有5个线程中有可能同时执行下面的代码
就是用findfirst,findnext查找某个目录里的文件然后读到
emaillist的tstrings里面,然后删除文件。
由于是在线程中执行查找,会不会有读到同一个文件的可能性?
会不会发生要删除一个正在读的文件面出错的可能性?
/////////////////////////////////
if findfirst(wildfile,fileattrs,sr)=0 then
begin
repeat
if sr.attr<>fadirectory then
begin
filetoopen:=filename+sr.name;
emaillist.clear;
emaillist.loadfromfile(filetoopen);
deletefile(filetoopen);
amxlist.clear;
querymx(amxlist,emaillist.strings[0]);
/////////////////////////////////
sendemail(amxlist,emaillist);
////////////////////////////////////
end;
until findnext(sr)<>0;
findclose(sr);
end;
推荐阅读
应该可能吧。
很有可能,试试用信号量互斥体等同步方法。
.

讨论区