Index: /branches/eam_branch_20080719/pswarp/src/pswarpThreadLauncher.c
===================================================================
--- /branches/eam_branch_20080719/pswarp/src/pswarpThreadLauncher.c	(revision 18747)
+++ /branches/eam_branch_20080719/pswarp/src/pswarpThreadLauncher.c	(revision 18747)
@@ -0,0 +1,53 @@
+# include "pswarp.h"
+
+bool pswarpThreadTest (psArray *args) {
+
+    pthread_t id = pthread_self();
+
+    // int dtime = 500000*drand48();
+
+    int dtime = (drand48() > 0.5) ? 500000 : 10000;
+    bool status = (drand48() > 0.9) ? false : true;
+
+    usleep (dtime);
+    fprintf (stderr, "in thread %lu, args %s and %s, dtime %d, status %d\n", id, (char *) args->data[0], (char *) args->data[1], dtime, status);
+
+    return status;
+}
+
+// each thread runs this function, starting a new job when it finished with an old one
+// it is called with a (void *) pointer to its own thread pointer
+void *pswarpThreadLauncher (void *data) {
+
+    psThread *self = data;
+    psThreadJob *job = NULL;
+
+    while (1) {
+
+	// if we get an error, just wait until we are cleared or killed
+	while (self->fault) {
+	    usleep (10000);
+	}
+
+	// request a new job, if there are none available, sleep a bit
+	// we have to lock here so the job queue cannot be empty yet no threads busy
+	psThreadLock();
+	while ((job = psThreadJobGet ()) == NULL) {
+	    psThreadUnlock();
+	    usleep (10000);
+	}
+	self->busy = true;
+	psThreadUnlock();
+
+	// list all allowed job types here
+	if (!strcmp (job->type, "THREAD_TEST")) {
+	    bool status = pswarpThreadTest (job->args);
+	    if (!status) {
+		self->fault = true;
+	    }
+	    // we do not have to lock here because this transition is not tied to the job queue
+	    self->busy = false;  
+	    continue;
+	}
+    }  
+}
