Jump to content
Sonjli

DSiWaitForTwoObjects

Recommended Posts

Hello,

I am trying to start communication between two threads.

The first thread is not mine, it come from an external component library (always Delphi).

This component has an event "OnSomethingHappens" that fires in a separate thread.

So, in this event I use the OTL Communication system. For example: lMyTask.Comm.Send(WM_MYMESSAGE, MyObject);

In my task I do a simple loop like this:

 

                  while Task.Comm.Receive(lMsg) do
                  begin
                     if lMsg.MsgID = WM_MYMESSAGE then
                       etc.

 

But watching at OTL demos I see that you do somthing like this:

 

  repeat
    case DSiWaitForTwoObjects(task.TerminateEvent, task.Comm.NewMessageEvent, false, task.Param['Delay']) of
      WAIT_OBJECT_1:
        begin
          while task.Comm.Receive(msgID, msgData) do begin
            if msgID = MSG_CHANGE_MESSAGE then
              msg := msgData;
          end;
        end;
      WAIT_TIMEOUT:
        task.Comm.Send(0, msg);
      else
        break; //repeat
    end;
  until false;

 

Sorry for my ignorance but I don't understand why you use the DSiWaitForTwoObjects and what it means.

As I am having some problems in my loop, I think they are related to this use case... so can you explain, please?

 

Thanks again,

Eddy

 

Share this post


Link to post

DSiWaitForTwoObjects is just a shortcut which calls WaitForMultipleObjects Windows API with two handles. In this case it will return with status WAIT_TIMEOUT when a timeout elapses, WAIT_OBJECT_1 when task.Comm.NewMessageEvent is signalled or WAIT_OBJECT_0 when task.TerminateEvent is signalled.

Share this post


Link to post

Ok, thank you as usual.

So, I have this strange behavoiur:

The task receiving messages sometimes slow very down, and I can see 30/40 messages queued from the "external" thread, but only one elaboration of my task loop.

So in this situation the queue risks to be full very quickly (1000 messages I read in docs).

But I don't know why this happens... a loop too thight?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×