summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorunknown <jani@prima.mysql.com>2000-11-24 02:04:25 +0200
committerunknown <jani@prima.mysql.com>2000-11-24 02:04:25 +0200
commitc754d3318624c31e84772edb7d053da4628fd7ca (patch)
treefc6f4e4a0bf80575c6c436014fcb2d082e7df99c /client
parente94b4ebf2bc64710336597445529887640908cc4 (diff)
parent637a758b836d41b86f3e5bae4e4a55ae7272bcd5 (diff)
downloadmariadb-git-c754d3318624c31e84772edb7d053da4628fd7ca.tar.gz
Merge
Docs/manual.texi: SCCS merged
Diffstat (limited to 'client')
-rw-r--r--client/thimble.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/client/thimble.cc b/client/thimble.cc
new file mode 100644
index 00000000000..1c4fdd97ed2
--- /dev/null
+++ b/client/thimble.cc
@@ -0,0 +1,89 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static void spawn_stern_thread(pthread_t *t);
+static int act_goofy(void);
+static void *be_stern(void *);
+
+static struct {
+ pthread_mutex_t lock;
+ pthread_cond_t cond;
+ int msg;
+} comm = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 };
+
+int
+main(void)
+{
+ pthread_t t;
+ spawn_stern_thread(&t);
+
+ while (act_goofy() != 0)
+ /* do nothing */;
+
+ pthread_exit(NULL);
+
+ /* notreached */
+ return EXIT_SUCCESS;
+}
+
+static void spawn_stern_thread(pthread_t *t)
+{
+ pthread_attr_t attr;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (pthread_create(t, &attr, be_stern, NULL) != 0)
+ exit(EXIT_FAILURE);
+
+ pthread_attr_destroy(&attr);
+}
+
+static int act_goofy(void)
+{
+ int ret;
+ char buf[30];
+
+ fputs("Are you ready to act goofy (Y/n)? ", stdout); fflush(stdout);
+ fgets(buf, sizeof(buf), stdin);
+ pthread_mutex_lock(&comm.lock);
+ if (buf[0] == 'y' || buf[0] == '\n') {
+ fputs("** Waawlwalkwwwaa!!\n", stdout); fflush(stdout);
+ ++comm.msg;
+ ret = 1;
+ }
+ else {
+ fputs("OK, I hate you. Let me go.\n", stdout); fflush(stdout);
+ comm.msg = -1;
+ ret = 0;
+ }
+ pthread_mutex_unlock(&comm.lock);
+ pthread_cond_signal(&comm.cond);
+
+ return ret;
+}
+
+static void *be_stern(void *v __attribute((unused)))
+{
+ int msg;
+ for (;;) {
+ pthread_mutex_lock(&comm.lock);
+ while (comm.msg == 0)
+ pthread_cond_wait(&comm.cond, &comm.lock);
+ msg = comm.msg;
+ comm.msg = 0;
+ pthread_mutex_unlock(&comm.lock);
+
+ if (msg < 0)
+ break; /* the goofy one learned a lesson! */
+
+ fputs("I HAVE TO BE STERN WITH YOU!\n", stderr);
+ fprintf(stderr, "I should give you %d lashes.\n", msg);
+ sleep(msg);
+ }
+
+ fputs("You are NOTHING!\n", stderr);
+ return NULL;
+}