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?
Discussed in #3759
Originally posted by cxiao December 27, 2022
In the Python API, the
mainthreadmodule and several classes in thepluginmodule 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:
filemetadata.FileMetadatafrom a background thread?In IDA, the IDA C++ SDK has the
THREAD_SAFEkeyword, which has the following description:As of IDA 7.2, IDAPython enforces the following behaviour for functions not marked with this keyword:
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?