Only check for empty task objects when NDEBUG is not defined.
Fixed atomic memory ordering on event_task
Replaced implicit bool conversion on task with a valid() member function
Refactored handling of per-thread event objects.

Events for internal threads are now stored in the thread data structure,
and events for external threads are allocated on the stack.