Threaded internal pthread_cond_t always initialized (expensive), though potentially not used
pthread_cond_t facilitates wait()/notify() functionality, which aren't needed in the majority of cases. However, the monitor always allocates them, and this accounts for the large majority of the time spent when creating new Threaded objects.
Ways this could be avoided:
- (ng only) Split wait/notify stuff into its own class, leaving
ThreadedBaseeven more basic - Lazy-init pthread_cond_t (I haven't explored whether this is safe or not).
Lazy initialization isn't an option since it's possible for multiple threads to try to use wait() simultaneously without using synchronized(). This would lead to a data race and memory leak.
If we decide to go with a separate class for this, ThreadedEvent would make sense, with a similar API to Python's threading.Event.
This would also simplify the majority use-case of wait() and notify() by avoiding the need for boilerplate synchronized blocks, amongst other things - the vast majority of uses of wait/notify involve some kind of boolean condition flag.