Added mutex lock timeout functionality to avoid permanent deadlocks.