if run speed is average (30 times/second)thread work fine but when speed up 60 times/second access violation after short time running (about 10 minute)
Any suggestion ?
Here is my code
---------------------------------
procedure TVoteDBThread.Execute;
var
pSMS
E2S;
NewRec: pS2E;
dbInsert: pVoteData;
i: integer;
kq: integer;
dLength: integer;
fChar: Char;
pMsg: pThrMsg;
begin
dLength:=0;
kq:=-1;
while not Terminated do
begin
try
kq:=MyQueue.ReadItem(pointer(pSMS),dLength,2000);
finally
if ((kq=BUFF_NO_ERROR) and (not Terminated)) then
begin
try
if (not MyOrclAvailable) and (not Terminated) then
if SecondsBetween(fDateFailure,now)>=10 then begin
fDateFailure:=now;
OraSession.LogOn;
MyOrclAvailable:=true;
New(pMsg);
pMsg^:='re-Connect successfully !';
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(pMsg,sizeof(pMsg^),2000) BUFF_NO_ERROR then
Dispose(pMsg);
end;
if MyOrclAvailable and (not Terminated) then begin
oSMS_in.Clear;
oSMS_in.SetAttr('Sendernr',trim(pSMS^.SenderNr));
oSMS_in.SetAttr('SMS',trim(pSMS^.SMS));
oSMS_in.SetAttr('Service_center',trim(pSMS^.ServiceCenter));
EnterCriticalSection(FDestSection^);
fChar:=(Flag + threadnum-1)^;
LeaveCriticalSection(FDestSection^);
if fChar='R' then begin
if OraSession.CheckConnection(true) ccError then
Loadmatchs;
EnterCriticalSection(FDestSection^);
(Flag + threadnum-1)^:='S';
LeaveCriticalSection(FDestSection^);
//SendMsg(format('Reload data in thread %d ',[threadnum]));
New(pMsg);
pMsg^:='re-Connect successfully !';
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(pMsg,sizeof(pMsg^),2000) BUFF_NO_ERROR then
Dispose(pMsg);
end;
ProcessSMS;
if intVoteSucces=1 then begin
New(dbInsert);
//dbInsert:=AllocMem(sizeof(TInsertData));
dbInsert^.Subject:=oData.GetAttr('subject_id');
dbInsert^.PlayerChoice:=oData.GetAttr('player_choice');
dbInsert^.MagicNumber:=oData.GetAttr('magic_number');
dbInsert^.VoteType:=oData.GetAttr('vote_type');
dbInsert^.VoteTime:=oData.GetAttr('Vote_time');
dbInsert^.Mobile:=oData.GetAttr('Sender_nr');
dbInsert^.ServiceCenter:=oData.GetAttr('Service_center');
dbInsert^.SMS:=pSMS^.SMS;
dbInsert^.Provider:=oData.GetAttr('provider_id');
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(dbInsert,sizeof(dbInsert^),2000) BUFF_NO_ERROR then
Dispose(dbInsert);
end;
for i:=0 to oSMSList.ElementCount-1 do begin
New(NewRec);
NewRec^.ThreadID:=ThreadNum;
Newrec^.SessionId:=pSMS^.SessionID;
NewRec^.ServiceCenter:=oSMSList.GetAttr('Service_number');
NewRec^.Mobile:=oSMSList.GetAttr('mobile_number');
NewRec^.Service_code:=oSMSList.GetAttr('Service_code');
NewRec^.Flash:=oSMSList.GetAttr('Flash');
NewRec^.Err_code:=oSMSList.GetAttr('Error_code');
NewRec^.SMS:=oSMSList.GetAttr('SMS');
NewRec^.cmd_id:= oSMSList.GetAttr('CMD_ID');
NewRec^.provider_id:= oSMSList.GetAttr('PROVIDER_ID');
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(NewRec,sizeof(NewRec^),2000) BUFF_NO_ERROR then
Dispose(NewRec);
//PostMessage(RecipientHandle,WM_DATA_FROM_THREAD,wparam(SMS_OUT),lParam(newrec));
end;
PostMessage(RecipientHandle,WM_DATA_FROM_THREAD,0,0);
end;
except
on e: EOracleError do begin
case e.ErrorCode of
03113: //End of file on communication chanel
MyOrclAvailable:=false;
03114: //Not connected to Oracle
MyOrclAvailable:=false;
12571: //TNS-12571 TNS
acket writer failure
MyOrclAvailable:=false;
end;
fDateFailure:=Now;
//SendMsg(e.Message);
New(pMsg);
pMsg^:=copy(e.message,1,190);
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(pMsg,sizeof(pMsg^),2000) BUFF_NO_ERROR then
Dispose(pMsg)
else
PostMessage(RecipientHandle,WM_DATA_FROM_THREAD,0,0);
end ;
end;
Dispose(pSMS);
end
{ else
SendMsg(format('Loi doc buffer in thread %d: %d ',[threadnum,kq]));
}
end;
{
if not Terminated then
begin
end;// [more processing]
}
end; // of Read thread main execution loop
end;
---------------------------------
Any suggestion ?
Here is my code
---------------------------------
procedure TVoteDBThread.Execute;
var
pSMS
NewRec: pS2E;
dbInsert: pVoteData;
i: integer;
kq: integer;
dLength: integer;
fChar: Char;
pMsg: pThrMsg;
begin
dLength:=0;
kq:=-1;
while not Terminated do
begin
try
kq:=MyQueue.ReadItem(pointer(pSMS),dLength,2000);
finally
if ((kq=BUFF_NO_ERROR) and (not Terminated)) then
begin
try
if (not MyOrclAvailable) and (not Terminated) then
if SecondsBetween(fDateFailure,now)>=10 then begin
fDateFailure:=now;
OraSession.LogOn;
MyOrclAvailable:=true;
New(pMsg);
pMsg^:='re-Connect successfully !';
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(pMsg,sizeof(pMsg^),2000) BUFF_NO_ERROR then
Dispose(pMsg);
end;
if MyOrclAvailable and (not Terminated) then begin
oSMS_in.Clear;
oSMS_in.SetAttr('Sendernr',trim(pSMS^.SenderNr));
oSMS_in.SetAttr('SMS',trim(pSMS^.SMS));
oSMS_in.SetAttr('Service_center',trim(pSMS^.ServiceCenter));
EnterCriticalSection(FDestSection^);
fChar:=(Flag + threadnum-1)^;
LeaveCriticalSection(FDestSection^);
if fChar='R' then begin
if OraSession.CheckConnection(true) ccError then
Loadmatchs;
EnterCriticalSection(FDestSection^);
(Flag + threadnum-1)^:='S';
LeaveCriticalSection(FDestSection^);
//SendMsg(format('Reload data in thread %d ',[threadnum]));
New(pMsg);
pMsg^:='re-Connect successfully !';
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(pMsg,sizeof(pMsg^),2000) BUFF_NO_ERROR then
Dispose(pMsg);
end;
ProcessSMS;
if intVoteSucces=1 then begin
New(dbInsert);
//dbInsert:=AllocMem(sizeof(TInsertData));
dbInsert^.Subject:=oData.GetAttr('subject_id');
dbInsert^.PlayerChoice:=oData.GetAttr('player_choice');
dbInsert^.MagicNumber:=oData.GetAttr('magic_number');
dbInsert^.VoteType:=oData.GetAttr('vote_type');
dbInsert^.VoteTime:=oData.GetAttr('Vote_time');
dbInsert^.Mobile:=oData.GetAttr('Sender_nr');
dbInsert^.ServiceCenter:=oData.GetAttr('Service_center');
dbInsert^.SMS:=pSMS^.SMS;
dbInsert^.Provider:=oData.GetAttr('provider_id');
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(dbInsert,sizeof(dbInsert^),2000) BUFF_NO_ERROR then
Dispose(dbInsert);
end;
for i:=0 to oSMSList.ElementCount-1 do begin
New(NewRec);
NewRec^.ThreadID:=ThreadNum;
Newrec^.SessionId:=pSMS^.SessionID;
NewRec^.ServiceCenter:=oSMSList.GetAttr('Service_number');
NewRec^.Mobile:=oSMSList.GetAttr('mobile_number');
NewRec^.Service_code:=oSMSList.GetAttr('Service_code');
NewRec^.Flash:=oSMSList.GetAttr('Flash');
NewRec^.Err_code:=oSMSList.GetAttr('Error_code');
NewRec^.SMS:=oSMSList.GetAttr('SMS');
NewRec^.cmd_id:= oSMSList.GetAttr('CMD_ID');
NewRec^.provider_id:= oSMSList.GetAttr('PROVIDER_ID');
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(NewRec,sizeof(NewRec^),2000) BUFF_NO_ERROR then
Dispose(NewRec);
//PostMessage(RecipientHandle,WM_DATA_FROM_THREAD,wparam(SMS_OUT),lParam(newrec));
end;
PostMessage(RecipientHandle,WM_DATA_FROM_THREAD,0,0);
end;
except
on e: EOracleError do begin
case e.ErrorCode of
03113: //End of file on communication chanel
MyOrclAvailable:=false;
03114: //Not connected to Oracle
MyOrclAvailable:=false;
12571: //TNS-12571 TNS
MyOrclAvailable:=false;
end;
fDateFailure:=Now;
//SendMsg(e.Message);
New(pMsg);
pMsg^:=copy(e.message,1,190);
while QueueOut.Full do
sleep(10);
if QueueOut.WriteItem(pMsg,sizeof(pMsg^),2000) BUFF_NO_ERROR then
Dispose(pMsg)
else
PostMessage(RecipientHandle,WM_DATA_FROM_THREAD,0,0);
end ;
end;
Dispose(pSMS);
end
{ else
SendMsg(format('Loi doc buffer in thread %d: %d ',[threadnum,kq]));
}
end;
{
if not Terminated then
begin
end;// [more processing]
}
end; // of Read thread main execution loop
end;
---------------------------------