Using the library in a multithreading environment
In general, the library is thread-safe, but not process-safe.
Here are some implementation details:
- There are two locks: A Property Lock (P-Lock ) for camera properties and a Grabbing Lock (G-Lock) which protects the image acquisition calls.
For example, if one thread calls FG_set_gain() and a second one FG_set_black(), both calls are serialized. But during these calls, a third thread can capture images with FG_get_image() / FG_append_image() without any blocking.
- Any function blocks until the work is done, or until a timeout or error occurs.
Please note that some sensors use new settings with the next frame, but the function may return earlier.
- There are some functions which not require the P/G-Lock to be thread-safe.
- It is not allowed to use the library with more than one process at the same time, in this case the behavior is unpredictable.
Below is a table with all functions and how they are locked
Functions vs. synchronization scope
Synchronized by | Function(s) |
G-SEM | FG_get_image() |
P-SEM | FG_alloc_image(), FG_free_image(), FG_trigger_image(), FG_stop_image()
FG_set_aoi(), FG_get_aoi(), FG_set_trigger_mode(), FG_get_trigger_mode(), FG_set_black(), FG_get_black(), FG_set_gain(), FG_get_gain(), FG_set_gain_rgb(), FG_get_gain_rgb(), FG_set_shutter_time(), FG_get_shutter_time(), FG_set_special_option(), FG_get_special_option() |
no sync / other | FG_install_camera(), FG_uninstall_camera(), FG_get_camera_type(), FG_append_image(), FG_save_image(), FG_get_last_error(), FG_get_version() |