Skip to content

Approach to working with libraries that invoke callbacks from foreign threads #28

@dom96

Description

@dom96

This was raised by @gokr. He started writing a brilliant project in Nim but ran into trouble when he needed to use the pharo MQTT library (library link and nim wrapper).

This library exposes an "asynchronous" API which works by using threads in the background. Using this API is necessary to achieve asynchronous operation for Jester.


Side node

As I am writing this, another idea came to me, perhaps @gokr will be willing to try it out:

Use the library's synchronous API in a Nim thread. This will ensure that all threads are handled by nim and thus there should be no trouble.


Indeed, the issues seem to arise when attempting to integrate these "foreign threads" with Nim's handling of threads (per-thread GC). You can see @gokr attempting to get this to work using setupForeignGC.

TL;DR

I have no idea how to wrap libraries that call into Nim code via a call-back from a foreign thread.
We need to figure out the best way to accomplish this and document it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions