gabr42 / gabr42/OmniThreadLibrary
Improve or warn about ReceiveWait and creating task with function
- Dominant language
- Pascal
- Stars
- 513
- Forks
- 147
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
i just figured out that ReceiveWait will also receive internal messages. Lets say i create a task and say execute the _Execute_ procedure:
```
CreateTask(TMyOmniWorker.Create(True)).MonitorWith(FOmniEM).Run(@TMyOmniWorker.Execute);
```
Inside the _Initialize_ function i make a checkup if the task is allowed to process:
```
LFound := False;
repeat
// This will also receive the @TMyOmniWorker.Execute message!
task.Comm.ReceiveWait(LMessage, 1000 * 5);
LFound := (((LMessage.MsgID = MSG_CONTINUE_TASK) or (LMessage.MsgID = MSG_QUIT_TASK)) and (LMessage.MsgData[0].AsInt64 = task.UniqueID));
/// START Execute Fix
if not LFound then
task.Comm.OtherEndpoint.Send(LMessage);
until LFound;
```
Here the problem appears. It took some time to figure it out. The _ReceiveWait_ function catches the Execute message and removes it from the internal list. In the end the _Initialize_ function is finished, but the _Execute_ procedure gets never called. Obviously this is really clear if you read this, but you have to **know** that the same message channel is used.
In order to "fix" the problem i receive the Execute message and send it again to the TMyOmniWorker/OtherEndpoint.
http://geskill.bplaced.net/hp/other/OmniWorkerTestwithMonitor.zip
best regards
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.