Index: test/Makefile.am
===================================================================
--- test/Makefile.am	(revision 29)
+++ test/Makefile.am	(revision 32)
@@ -1,5 +1,5 @@
 INCLUDES=-I$(top_srcdir)/src
 
-noinst_PROGRAMS=testevent testlocsock testblkstream
+noinst_PROGRAMS=testevent testlocsock testblkstream testmutex
 if TARGET_API_POSIX
 noinst_PROGRAMS+=testrandom
@@ -33,4 +33,13 @@
 endif
 
+testmutex_SOURCES=testmutex.cc
+testmutex_LDADD=../src/xplcommon/libxplcommon.la
+if TARGET_API_POSIX
+testmutex_LDADD+=-lpthread
+endif
+if TARGET_API_WIN32
+testmutex_LDFLAGS=-static-libgcc -static-libstdc++
+endif
+
 testrandom_SOURCES=testrandom.cc
 testrandom_LDADD=../src/xplcommon/libxplcommon.la
Index: test/testmutex.cc
===================================================================
--- test/testmutex.cc	(revision 32)
+++ test/testmutex.cc	(revision 32)
@@ -0,0 +1,163 @@
+// 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 <cstdlib>
+#include <cstdio>
+#include <cassert>
+
+#include <signal.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+
+using xplcommon::Thread;
+using xplcommon::Mutex;
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread1 : public Thread
+{
+private:
+    Mutex& mutex;
+
+public:
+    Thread1(Mutex& mutex);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread1::Thread1(Mutex& mutex) :
+    mutex(mutex)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread1::run()
+{
+    printf("Thread1::run: locking mutex\n");
+    mutex.lock();
+    printf("Thread1::run: locked mutex, sleeping...\n");
+
+    sleep(5000);
+
+    printf("Thread1::run: woke up, releasing mutex\n");
+    mutex.unlock();
+
+    printf("Thread1::run: released mutex, sleeping\n");
+
+    sleep(1000);
+
+    printf("Thread1::run: woke up, locking mutex\n");
+    mutex.lock();
+    printf("Thread1::run: locked mutex, releasing\n");
+    mutex.unlock();
+
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread2 : public Thread
+{
+private:
+    Mutex& mutex;
+
+public:
+    Thread2(Mutex& mutex);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread2::Thread2(Mutex& mutex) :
+    mutex(mutex)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread2::run()
+{
+    printf("Thread2::run: sleeping\n");
+    sleep(1000);
+
+    printf("Thread2::run: woke up, trying to lock mutex...\n");
+
+    while(!mutex.tryLock()) {
+        sleep(200);
+    }
+
+    printf("Thread2::run: locked mutex, sleeping...\n");
+    sleep(5000);
+    printf("Thread2::run: woke up, releasing mutex\n");
+    mutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+    Mutex mutex;
+
+    Thread1 thread1(mutex);
+    Thread2 thread2(mutex);
+
+    printf("Starting threads\n");
+    thread1.start();
+    thread2.start();
+
+
+    printf("Waiting for thread1\n");
+    thread1.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:
