Implemented worker_thread function.