helper::login() and helper::logout() functions (and several other member functions with various return types and # of params and param types) are called on the main thread. In the implementations of these functions, the corresponding internal functions are to be enqueued in a queue, and the background thread calls these internal functions in the order in which they were enqueued. So something like this: