Hi, I have two threads, the main thread and the client thread. The purpose of the client thread is to provide non-blocking request-reply network functionality (using ZeroMQ lib). Creating and starting the client thread goes like this:
//from the main thread
FClientThread.Create('tcp://localhost:5020');
FClientThread.Start;
Sending a request goes like this:
//from the main thread
FClientThread.SendRequest('im_requesting_stuff',-1,'give_it_to_me');
Some of the variables are not being synchronized even waiting for them like so:
procedure TClientThread.SendRequest(ACode: string; ATrialIndex: integer;
ARequest: string);
begin
// BUG:These vars are being filled with the last values
FRequest := ARequest;
FCode := ACode;
FTrialIndex := IntToStr(ATrialIndex);
RTLeventSetEvent(FRTLEvent);
end;
procedure TClientThread.Execute;
var
AMessage : UTF8String;
begin
while not Terminated do
begin
AMessage := '';
RTLeventWaitFor(FRTLEvent);
FRequester.send( FRequest );
FRequester.recv( AMessage );
// BUG:These vars are being filled with the last values
// ('FTrialIndex', 'AMessage', 'FCode')
FMsg := #40#39 + FTrialIndex + #39#44#32#39 + AMessage + #39#44#32#39 + FCode + #39#41;
Synchronize( @Showstatus );
end;
end;
Strangely enough, the commented bug occurs ONLY if SendRequest is called multiple times in very short intervals.
Any suggestions?
Best Regards,
Rafael