Comments on: The Plugin SDK Is Not Even Remotely Thread-Safe https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/ Developer resources for the X-Plane flight simulator Thu, 21 Feb 2019 11:15:25 +0000 hourly 1 https://wordpress.org/?v=6.6.1 By: Dominik Pospisil https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33223 Thu, 21 Feb 2019 11:15:25 +0000 http://developer.x-plane.com/?p=39443#comment-33223 The out-of process plugins is great idea! No more plugins interference and incompatibilities! Please, please, make it happen!! I always wanted to write plugin to run in separate process but inability to share gl context prevented me from doing so.

]]>
By: Bob Thomas https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33221 Wed, 20 Feb 2019 13:31:59 +0000 http://developer.x-plane.com/?p=39443#comment-33221 I hope XPUIPC isn’t using background threads to make API calls as it’s no longer developed, so unlikely to get an update/fix, and several useful tools rely on it.

]]>
By: Ben Supnik https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33213 Sat, 16 Feb 2019 16:57:15 +0000 http://developer.x-plane.com/?p=39443#comment-33213 In reply to Mark Parker.

You _may_ call any XPLM call from inside any XPLM callback, because the callbacks are always delivered on the main thread. The rule of the XPLM is “call us only on the thread on which we call you”, and in practice that thread has always been the main thread. We are probably never going to change that because UI callbacks naturally come from the main thread, so if we have to pick one, that’s the sane one to pick.

So from a flight loop callback, you can call XPLM routines to read/write datarefs, create windows, etc.

Way back in the day, there were _further_ restrictions, e.g. if you registered a flight loop from inside another flight loop callback, the XPLM would intermittently blow up; we had a Lot of fine print guidelines. All of that was fixed in the XPLM 2 for X-Plane 9; for v9, 10 and 11, you can call any other XPLM call from any XPLM call. (I think this even includes deleting an object from within its own callback.)

]]>
By: Mark Parker https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33208 Sat, 16 Feb 2019 03:04:56 +0000 http://developer.x-plane.com/?p=39443#comment-33208 In reply to Ben Supnik.

does this mean we may or may not make xplm calls inside a flight loop callback now?

]]>
By: Ben Supnik https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33200 Fri, 15 Feb 2019 13:18:30 +0000 http://developer.x-plane.com/?p=39443#comment-33200 In reply to Helge Schroeder.

Right – but this is a data point specific to sim-connect. There’s nothin fundamental about the sim-connect design that would make it fundamentally more expensive than synchronous plugins.

]]>
By: Helge Schroeder https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33199 Fri, 15 Feb 2019 12:35:10 +0000 http://developer.x-plane.com/?p=39443#comment-33199 In reply to Ben Supnik.

The achieved frame rate is crucial. If I deactivate SimConnect in my plugin, it will increase by one frame. With a total loss of 1.5 frames by my plugin that’s a big part. By contrast, the proportion of the map window drawn at 15 Hz is negligible.

]]>
By: Ben Supnik https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33197 Thu, 14 Feb 2019 22:10:42 +0000 http://developer.x-plane.com/?p=39443#comment-33197 In reply to Helge Schroeder.

What makes you say that an asynchronous interface would cause “a lot of extra” load on the processor?

]]>
By: Ben Supnik https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33196 Thu, 14 Feb 2019 22:09:31 +0000 http://developer.x-plane.com/?p=39443#comment-33196 In reply to xplanefan.

The flight loop does not _wait_ for plugins (where by “wait” I mean sleep the thread by blocking on an OS sync mechanism like a semaphore). Plugins are executed _synchronously_ on the main thread non-concurrently to the FM, so your plugin callback’s execution time is part of the “critical path” of the main thread through the sim loop.

There are concurrent worker threads in X-Plane and they are able to do a variety of background work, some of which is picked up within the frame and some of which is picked up after several frames. Plugins do not have access to this mechanism, except when calling XPLMLoadObjectAsync – in that case, the work of loading and building the OBJ file is done on this background pool and picked up later.

]]>
By: Helge Schroeder https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33193 Thu, 14 Feb 2019 18:30:11 +0000 http://developer.x-plane.com/?p=39443#comment-33193 Unfortunately, an asynchronous interface causes a lot of extra load on the processor. I do this experience daily with FSX/Prepar3d SimConnect. As a developer of the plugin FSTramp, I even think about leaving the SimConnect interface partially and switching to the simple FSX-gauge interface to read and write variables. This is similar to XPLM and therefore fast.

]]>
By: xplanefan https:/2019/02/the-plugin-sdk-is-not-even-remotely-thread-safe/#comment-33192 Thu, 14 Feb 2019 18:00:00 +0000 http://developer.x-plane.com/?p=39443#comment-33192 Matlab?! Bless ya’ll’s hearts (and those of any grad students in that wake). “Let them eat VBA”!

Doesn’t the flight loop wait for each plugin to finish? Serially? When I inject a sleep(1) into a plugin, FPS = 1 as well. Ergo, if the master plugin thread forces a join after spawning a batch in which each worker is known to invoke a different API call, where is the harm?

I suppose another way of asking is: is the worker that loops through the plugins not the only concurrently running thread in the xplane universe even though what my eyes see on the screen doesn’t update?

]]>