Convert the task->flags to atomic_uint and use atomic_fetch_or and...
Convert the task->flags to atomic_uint and use atomic_fetch_or and atomic_fetch_and to set and clear flags
Convert the task->flags to atomic_uint and use atomic_fetch_or and atomic_fetch_and to set and clear flags