Skip to content

Document which operations which are only safe to be performed on the main thread #3769

@plafosse

Description

@plafosse

Discussed in #3759

Originally posted by cxiao December 27, 2022
In the Python API, the mainthread module and several classes in the plugin module offer functionality for performing work on background threads, as well as functionality for ensuring that certain operations are only run on the main thread (e.g. mainthread.execute_on_main_thread.

However, it is not clear what types of operations can only ever be safely executed on the main thread. The one I can think of immediately is operations that update the UI, but are there any others? For example:

  • Is it safe to update settings (regardless of whether they are user, project, or resource scope) from a background thread?
  • Is it safe to perform file operations on the underlying BNDB via the functionality exposed by filemetadata.FileMetadata from a background thread?

In IDA, the IDA C++ SDK has the THREAD_SAFE keyword, which has the following description:

#define THREAD_SAFE
Functions callable from any thread are marked with this keyword.

As of IDA 7.2, IDAPython enforces the following behaviour for functions not marked with this keyword:

IDAPython: all functions not marked as THREAD_SAFE in the C++ SDK, will now check that they are being called from the main thread, avoiding possible corruption or crashes

Does the Binary Ninja core already enforce that certain functions can only ever be called from the main thread, and if so is it possible to expose information about that in the API docs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: APIIssue needs changes to the APIEffort: LowIssues require < 1 week of workImpact: MediumIssue is impactful with a bad, or no, workaround

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions