illuminated-g / lv-stream

A multi-threaded client/server library that serves as the base for TCP and WebSocket connections.
MIT License
0 stars 0 forks source link

Root Loop blocking #2

Open drjdpowell opened 1 year ago

drjdpowell commented 1 year ago

The Async called VIs are vulnerable to Root Loop blocking. This means that the User leaving a menu open will block new TCP connections. Solution is to cache a single VI reference. See how the Actor Framework does it in "Launch Actor". See original conversation where this was developed.

2023-01-30 10_33_44-Stream-TCP lvlib_TCP Server lvclass_Launch Server Loop vi Block Diagram on Basic

negentropicdev commented 1 year ago

Thanks for pointing this out, looks like it's time to develop some new habits and break my reliance on my easily placed snippets heh.

After reading through the linked discussion (and the NotARef discussion linked there) I'm thinking the best approach would be to open the reference during the Ctor call, cache it in the class data, and then reusing that reference from then on.

This ensures the following:

  1. VI reference opening is done during instance initialization only, the least likely time to cause issues with root loop blocking and if there is any, it is less likely to impact already running processes.
  2. This VI can remain re-entrant and not need to share the reference as non-reentrant code e.g. with a shift register or FB node. There may be a variable amount of time to start up a connection handler and other handlers for a stream type shouldn't be blocked.
  3. This could become the new standard pattern that gets reused through a lot of my code. Much of my code at several layers launches async handlers and will need to be updated.