The use of active_devices might not be thread safe if this library is used in more than one thread. Putting a new key in active_devices could cause it to be reallocated in one thread while another thread is reading which might cause undefined behaviour.