Functions for safe thread usage