Implemented condition variable.

Fixes #1030