Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with thread (TClientSocket and waiting)

7 views
Skip to first unread message

sonnic...@gmail.com

unread,
May 17, 2013, 8:48:06 AM5/17/13
to
Hi

I have a problem with a thread

I tried to my my TClientSocket in a thread, but now I face a new problem. The thread will stop and wait when I enter the repeat below - which not the idea of a thread.
The thread will create the command in the first line and pass it to the TClientSocket - however the thread is halted while waiting here - dont know why.
It gets to the timeout then sends data and I have a result 7ms later.

I move the TClientSocket com to a thread as I had another problem before - I could send data, but the "read event" would come after the time out.

Any ideas? (and yes it is friday evening and my brain is overloaded, I know)
I tried to set the threads priority highest - does not do the trick

information: the thread also handles some situtions by itself, such as replying ACK on on some errors

var
timeoutstart: Cardinal;
begin
// send command
FCommThread.GetDeviceTag;

// wait for answer
timeoutstart := GetTickCount;
repeat
if FCommThread.FAwaitingAnswer[CMD_GET_DEVICE_TAG] then
FDebugMsg(self, 'waiting...') // basically here while the thread is not doing anything
else
FDebugMsg(self, 'got data');

Sleep(200); // was 20
if (GetTickCount - timeoutstart) > 1000 then
begin
if FCommThread.FAwaitingAnswer[CMD_GET_DEVICE_TAG] then
raise Exception.Create('Failed to get data from SCHUCK') // ends here as data has not been sent out by the thread - then data is sent immidiately
else
raise Exception.Create('sadfasdfHoming: err'); // test
end;
until not FCommThread.FAwaitingAnswer[CMD_GET_DEVICE_TAG];

Result := FCommThread.FDeviceTag;
end;

Maarten Wiltink

unread,
May 18, 2013, 10:53:16 AM5/18/13
to
<sonnic...@gmail.com> wrote in message
news:5a472dd6-705a-4b12...@googlegroups.com...
[...]
> I tried to my my TClientSocket in a thread, but now I face a new
> problem. The thread will stop and wait when I enter the repeat
> below - which not the idea of a thread.

I'll respond to just this bit, as my knowledge of threads is limited.

Stopping and waiting _is_ the idea of a thread. You put something in
a different thread just so the waiting happens somewhere else, and
the main thread can go on its merry way responding to input and
updating the screen.

That said, the thread should be waiting for the socket, not the other
way around.

Groetjes,
Maarten Wiltink


0 new messages