ast: `ksh` doesn't use threads so what should the stance be vis-a-vis threads in plugins?

While resolving issue #276 I had to disable use of the __thread directive to make a var use thread local storage on OpenBSD 6.2. Obviously that is a hack that shouldn’t be needed. But it raises the question of whether threads should be explicitly allowed or disallowed in dynamically loaded builtins.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@kernigh

Does ksh have plugins?

Yes, KSH supports plugins, and has done so for some decades now (I think at least three decades). Plugins for KSH are rather trivial to load also. One way is to do it is via the KSH command ‘builtin’ as with:

$ builtin -f libfile plugin-name

Writing plugins is rather easy also with just a few caveats: they have to not leak memory nor file-descriptors (no auto cleanup like with process termination), and they must use SFIO for I/O on standard-input, standard-output, and standard-error. Use of SFIO is required because KSH proper can pass to the plugin a memory based file rather than a file-descriptor based file. Other than these caveats, much magic is possible. For example, using multi-threaded plugins, or starting one or more background threads to perform certain functions (like servers or other purposes). But any magic used must be carefully managed by the plugin writer, including having the plugin dynamically unloaded at pretty much any time with responsibility of the plugin writer to free up any allocated memory structures or terminating any background threads running within the plugin.

Yes, ksh supports plugins. Although the mechanism seems to be poorly documented and the last time I used ksh93u+ on a daily basis I was unaware plugins were supported. At the moment we do not have feature parity with the legacy Nmake based build. In part because as long as there are serious bugs in the core functionality (e.g., #398) that need to be fixed before anyone should even think about using this version it doesn’t make sense to work on fringe features like dynamically loaded plugins.