Index: test/Makefile.am
===================================================================
--- test/Makefile.am	(revision 32)
+++ test/Makefile.am	(revision 34)
@@ -1,5 +1,5 @@
 INCLUDES=-I$(top_srcdir)/src
 
-noinst_PROGRAMS=testevent testlocsock testblkstream testmutex
+noinst_PROGRAMS=testevent testlocsock testblkstream testmutex testcondvar
 if TARGET_API_POSIX
 noinst_PROGRAMS+=testrandom
@@ -42,4 +42,13 @@
 endif
 
+testcondvar_SOURCES=testcondvar.cc
+testcondvar_LDADD=../src/xplcommon/libxplcommon.la
+if TARGET_API_POSIX
+testcondvar_LDADD+=-lpthread
+endif
+if TARGET_API_WIN32
+testcondvar_LDFLAGS=-static-libgcc -static-libstdc++
+endif
+
 testrandom_SOURCES=testrandom.cc
 testrandom_LDADD=../src/xplcommon/libxplcommon.la
Index: test/testcondvar.cc
===================================================================
--- test/testcondvar.cc	(revision 34)
+++ test/testcondvar.cc	(revision 34)
@@ -0,0 +1,184 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <xplcommon/Thread.h>
+#include <xplcommon/Mutex.h>
+#include <xplcommon/CondVar.h>
+
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+
+#include <signal.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+
+using xplcommon::Thread;
+using xplcommon::Mutex;
+using xplcommon::CondVar;
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread1 : public Thread
+{
+private:
+    char id;
+
+    Mutex& mutex;
+
+    CondVar& condVar;
+
+public:
+    Thread1(char id, Mutex& mutex, CondVar& condVar);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread1::Thread1(char id, Mutex& mutex, CondVar& condVar) :
+    id(id),
+    mutex(mutex),
+    condVar(condVar)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread1::run()
+{
+    printf("Thread1[%c]::run: locking, and waiting on the condition\n", id);
+    mutex.lock();
+    condVar.wait(mutex);
+    printf("Thread1[%c]::run: condition received, waiting again\n", id);
+    condVar.wait(mutex);
+    printf("Thread1[%c]::run: condition received again, waiting with timeout\n", id);
+
+    bool result = condVar.wait(mutex, 5000);
+    printf("Thread1[%c]::run: waiting finished, %s\n", id,
+           result ? "received condition" : "timed out");
+    mutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread2 : public Thread
+{
+private:
+    Mutex& mutex;
+
+    CondVar& condVar;
+
+public:
+    Thread2(Mutex& mutex, CondVar& condVar);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread2::Thread2(Mutex& mutex, CondVar& condVar) :
+    mutex(mutex),
+    condVar(condVar)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread2::run()
+{
+    printf("Thread2::run: sleeping\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, signalling condition variable\n");
+    condVar.signal();
+
+    printf("Thread2::run: sleeping...\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, broadcasting condition variable\n");
+    condVar.broadcast();
+
+    printf("Thread2::run: sleeping...\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, signalling condition variable\n");
+    condVar.signal();
+
+    printf("Thread2::run: sleeping...\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, signalling condition variable\n");
+    condVar.signal();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+    Mutex mutex;
+    CondVar condVar;
+
+    Thread1 thread1('A', mutex, condVar);
+    Thread1 thread1a('B', mutex, condVar);
+    Thread2 thread2(mutex, condVar);
+
+    printf("Starting threads\n");
+    thread1.start();
+    thread1a.start();
+    thread2.start();
+
+    printf("Waiting for thread1\n");
+    thread1.join();
+    thread1a.join();
+    printf("Waiting for thread2\n");
+    thread2.join();
+    printf("Both threads returned\n");
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
