Clear Filters
Clear Filters

Preventing code interruption by events

6 views (last 30 days)
Christian Veenstra
Christian Veenstra on 17 Sep 2016
I have a program that listens for filesystem watcher events, to processes images as they arrive. It also exchanges information with another application over TCP. It has a GUI frontend. You can probably guess where this is going - synchronisation issues.
Unfortunately I've had trouble creating a minimum-example, since the TCP communication is a big part of my problem, but I will try and explain it...
When new images come in the program retrieves information by sending a message over TCP; the TCP server hears its request and responds (after a short time) with the information. If no events come in all is good.
However, if another event comes in (either a new image, something from a GUI button press, or something triggered by an analysis of the last image) during this time this new event "buds in" and begins executing its callback. This callback also communicates over TCP, and it will get the response from the earlier event. This is bad.
It seems that there is a interruptible/busyaction functionality for uicontrol events... but this doesn't help me because many of the events are from listener objects on filewatcher events.
I tried to make a "TCP busy" property in my tcp communication object, so that it labels itself as busy when waiting for a response, and used waitfor(tcpobj,"IsBusy",false) in the callback for all events. But this doesn't work because the new callback just waits indefinitely - the previous event will never finish because the new one has stolen execution priority.
I think what I really need is:
  • Something that I can put around my TCP code block to make it "modal" and prevent any events from being listened to while it executes. It seems this might be possible, as some matlab executions can't be interrupted (like when performing a large matrix operation) and any events (even, say, a user hitting CTRL-C) during that time just go into a queue. I can't seem to find how to add this functionality to my code, though.
  • Something like the interruptible/busyaction functionality, but for all callback events not just uicontrol events.
  • Some way for the newest callback function to return execution priority to the old callback, but still execute eventually. Maybe I can "rethrow" events somehow?
  • Some way for the two callback functions to communicate with each other and swap messages. I guess this would need to be extensible, though. What if I get 3 events at the same time?
Thanks...

Answers (0)

Categories

Find more on Manage Products in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!