Home > Back-end >  Delphi multithreaded synchronization in the critical region
Delphi multithreaded synchronization in the critical region

Time:09-30

Procedure TDispose. BatchRun;
Var
PicturePathlist: TStringlist;
I, j, passCnt unpassCnt passPercnt: Integer;
PictureCnt: integer;
//chat: Boolean;
Starttime, endtime, costtime: integer;
Speed: the real;
The begin
GroupBox3a. Visible:=false;
Button3a. Enabled:=false;

Starttime:=GetTickCount;
IsCanLookPic:=false;
If cbDebug1. Checked then
The begin
Showmessage (' please exit the debug mode);
IsCanLookPic:=true;
exit;
end;

Memo2a. Text:=' ';
If not directoryExists (folderPath + '\.. \ unqualified pictures') then the mkDir (folderPath + '\.. \ unqualified pictures');
If not directoryExists (folderPath + '\.. \ qualified pictures') then the mkDir (folderPath + '\.. \ qualified pictures');

DeleteDirectory (folderPath + '\.. Unqualified \ photos \ ');
DeleteDirectory (folderPath + '\.. \ qualified pictures \ ');
If sqlSearch (adoPicMsg1, 'select * from pictureMsg') then
SqlExecute (adoPicMsg1, 'delete * from pictureMsg');

SQLSTR:='insert into pictureMsg (';

PicturePathlist:=MakeFileList (folderPath, '*');
Memo2a. Lines. The Add (' this folder pictures there are + inttostr (PicturePathlist. Count) + 'a');
PassCnt:=0;
UnpassCnt:=0;
Progressbar1a. Position:=0;
Progressbar1a. Min:=0;
Progressbar1a. Max:=PicturePathlist. Count;
PictureCnt:=0;
For I:=0 to PicturePathlist. Do the count - 1
The begin
MainshowStr:=';
FieldNameStr:=';
FieldValueStr:=';
SQLSTR:='insert into pictureMsg (';


FileName:=Copy (ExtractFileName (PicturePathlist strings [I]), and 0, LastDelimiter ('. ', ExtractFileName (PicturePathlist. Strings [I])) - 1);
MainShowStr:=mainShowStr + 'file name: + fileName;

FieldNameStr:=fieldNameStr + 'name';
FieldValueStr:=fieldValueStr + '+' ' ' ' ' '+ fileName;

MainshowStr:=';
//chat:=true;
If LoadPicture (PicturePathlist strings [I]) then
The begin
If CheckBlueClarity then
The begin
If findEyes then
The begin
If CheckClarity then
The begin
Inc (passCnt);
Used by CopyFile (PChar (PicturePathlist strings [I]), PChar (folderPath + '\.. Qualified \ photos \ '+ ExtractFileName (PicturePathlist strings [I])), True);
FieldNameStr:=fieldNameStr + 'result';
FieldValueStr:=fieldValueStr + ', ' 'qualified' ';
Application. ProcessMessages;
End the else begin
Inc (unpassCnt);
Used by CopyFile (PChar (PicturePathlist strings [I]), PChar (folderPath + '\.. Unqualified \ photos \ '+ ExtractFileName (PicturePathlist. Strings [I])), True);
FieldNameStr:=fieldNameStr + 'result';
FieldValueStr:=fieldValueStr + ', ' 'unqualified' ' '.
Application. ProcessMessages;
end;
End the else begin
Inc (unpassCnt);
Used by CopyFile (PChar (PicturePathlist strings [I]), PChar (folderPath + '\.. Unqualified \ photos \ '+ ExtractFileName (PicturePathlist. Strings [I])), True);
FieldNameStr:=fieldNameStr + 'result';
FieldValueStr:=fieldValueStr + ', ' 'unqualified' ' '.
Application. ProcessMessages;
end;
End the else begin
Inc (unpassCnt);
Used by CopyFile (PChar (PicturePathlist strings [I]), PChar (folderPath + '\.. Unqualified \ photos \ '+ ExtractFileName (PicturePathlist. Strings [I])), True);
FieldNameStr:=fieldNameStr + 'result';
FieldValueStr:=fieldValueStr + ', ' 'unqualified' ' '.
Application. ProcessMessages;
end;
End the else begin
Inc (unpassCnt);
Used by CopyFile (PChar (PicturePathlist strings [I]), PChar (folderPath + '\.. Unqualified \ photos \ '+ ExtractFileName (PicturePathlist. Strings [I])), True);
FieldNameStr:=fieldNameStr + 'result';
FieldValueStr:=fieldValueStr + ', ' 'unqualified' ' '.
Application. ProcessMessages;
end;//if LoadPicture (PicturePathlist str9ings [I]) then


FieldNameStr:=fieldNameStr + ', folderPath ';
FieldValueStr:=fieldValueStr + ', ' '+ folderPath + "' "';

SQLSTR: SQLSTR=+ fieldNameStr + ') values (' + fieldValueStr + ') '.
SQLExecute (adoPicMsg1 SQLSTR);

Inc (PictureCnt);
Memo2a. Lines. The Add (',,,,,,,,, has been testing photos' + inttostr (PictureCnt) + 'a');
Progressbar1a. Position:=progressbar1a. Position + 1;

end;//for I:=0 to PicturePathlist. Do the count - 1
//PicturePathlist. Free;
SQLSearch (adoPicMsg1, 'select * from pictureMsg');
PassPercnt:=trunc (passCnt/(passCnt + unpassCnt) * 100 + 0.5);
Endtime:=GetTickCount;
Costtime:=endtime - starttime;
Speed:=(PictureCnt * 1000) div costtime;
Memo2a. Lines. The Add (' photos percent of pass='+ inttostr (passPercnt) +' % of qualified number='+ inttostr (passCnt) +', unqualified number='+ inttostr (unpassCnt)
='+ +', time consuming floattostr (costtime/1000) + 's speed=' + floattostr (speed) + 'a/s);
IsCanLookPic:=true;

GroupBox3a. Visible:=true;
Button3a. Enabled:=true;

end;




Procedure TDispose. Execute;//click on the button thread TDispose execution
The begin
FreeOnTerminate:=true;
Flock. Enter;
BatchRun;
Flock. Leave;
{Place thread code here}
end;




One CheckBlueClarity findEyes and CheckClarity three functions is to deal with image, look to whether accord with a standard back I use critical sections for multithreaded synchronization, the purpose is not suspended in mobile forms processing, the results achieved, but if I click the button to run a few times you will find more, the front three judge function judgment results will go wrong, some data will be chaos, would you please tell me what the solution to the great god? What's the problem with my program?

CodePudding user response:

null
  • Related