Add mutexes for thread-safe interaction.