2.3 Threading

BFD has limited support for thread-safety. Most BFD globals are protected by locks, while the error-related globals are thread-local. A given BFD cannot safely be used from two threads at the same time; it is up to the application to do any needed locking. However, it is ok for different threads to work on different BFD objects at the same time.

2.3.1 Thread functions.

typedef bool (*bfd_lock_unlock_fn_type) (void *);

2.3.1.1 _bfd_threading_enabled

Function: bool _bfd_threading_enabled (void);

Return true if threading is enabled, false if not.

2.3.1.2 bfd_thread_init

Function: bool bfd_thread_init (bfd_lock_unlock_fn_type lock, bfd_lock_unlock_fn_type unlock, void *data);

Initialize BFD threading. The functions passed in will be used to lock and unlock global data structures. This may only be called a single time in a given process. Returns true on success and false on error. On error, the caller should assume that BFD cannot be used by multiple threads. DATA is passed verbatim to the lock and unlock functions. The lock and unlock functions should return true on success, or set the BFD error and return false on failure. Note also that the lock must be a recursive lock: BFD may attempt to acquire the lock when it is already held by the current thread.

2.3.1.3 bfd_thread_cleanup

Function: void bfd_thread_cleanup (void);

Clean up any thread-local state. This should be called by a thread that uses any BFD functions, before the thread exits. It is fine to call this multiple times, or to call it and then later call BFD functions on the same thread again.

2.3.1.4 bfd_lock

Function: bool bfd_lock (void);

Acquire the global BFD lock, if needed. Returns true on success, false on error.

2.3.1.5 bfd_unlock

Function: bool bfd_unlock (void);

Release the global BFD lock, if needed. Returns true on success, false on error.