about summary refs log tree commit diff
path: root/linuxthreads/Examples/ex18.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-11-29 07:43:03 +0000
committerUlrich Drepper <drepper@redhat.com>2001-11-29 07:43:03 +0000
commit03a2c6475bd251773ddce5e9e5bb9b8d4c0baeab (patch)
treee3b83e302b2f166d9520df5dcfa0195fe051c2ba /linuxthreads/Examples/ex18.c
parente0e86ccb1d2848678b5c32f65bf6239ba5fb9d24 (diff)
downloadglibc-03a2c6475bd251773ddce5e9e5bb9b8d4c0baeab.tar.gz
glibc-03a2c6475bd251773ddce5e9e5bb9b8d4c0baeab.tar.xz
glibc-03a2c6475bd251773ddce5e9e5bb9b8d4c0baeab.zip
Update.
	* iconvdata/ibm1163.c: New file.
	* iconvdata/ibm1163.h: New file.
	* iconvdata/ibm1164.c: New file.
	* iconvdata/ibm1164.h: New file.
	* iconvdata/TESTS: Add entries for IBM1163 and IBM1164.
	* iconvdata/Makefile: Likewise.
	* iconvdata/testdata/IBM1163: New file.
	* iconvdata/testdata/IBM1163..UTF8: New file.
	* iconvdata/testdata/IBM1164: New file.
	* iconvdata/testdata/IBM1164..UTF8: New file.
	Patch by Masahide Washizawa <WASHI@jp.ibm.com>.

	* iconvdata/ibm1046.h: Optimize.  Remove duplicate mappings.
	* iconvdata/ibm1124.h: Likewise.
	* iconvdata/ibm1132.h: Likewise.
	* iconvdata/ibm1133.h: Likewise.
	* iconvdata/ibm1160.h: Likewise.
	* iconvdata/ibm1161.h: Likewise.
	* iconvdata/ibm1162.h: Likewise.
	* iconvdata/ibm856.h: Likewise.
	* iconvdata/ibm922.h: Likewise.
	* iconvdata/ibm930.h: Likewise.
	* iconvdata/ibm932.h: Likewise.
	* iconvdata/ibm933.h: Likewise.
	* iconvdata/ibm935.h: Likewise.
	* iconvdata/ibm937.h: Likewise.
	* iconvdata/ibm939.h: Likewise.
	* iconvdata/ibm943.h: Likewise.
	* iconvdata/ibm930.c: Pretty printing.
	* iconvdata/ibm937.c: Avoid access accross array boundary.
Diffstat (limited to 'linuxthreads/Examples/ex18.c')
-rw-r--r--linuxthreads/Examples/ex18.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/linuxthreads/Examples/ex18.c b/linuxthreads/Examples/ex18.c
new file mode 100644
index 0000000000..642f6b44cd
--- /dev/null
+++ b/linuxthreads/Examples/ex18.c
@@ -0,0 +1,112 @@
+/*
+ * Beat up the pthread_key_create and pthread_key_delete
+ * functions.
+ */
+
+#if 0
+#define CHATTY
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+const int beatup_iterations = 10000;
+const int num_threads = 30;
+const int max_keys = 500;
+
+struct key_list {
+  struct key_list *next;
+  pthread_key_t key;	
+};
+
+struct key_list *key_list;
+pthread_mutex_t key_lock = PTHREAD_MUTEX_INITIALIZER;
+
+/*
+ * Create a new key and put it at the tail of a linked list.
+ * If the linked list grows to a certain length, delete a key from the
+ * head of * the list. 
+ */
+
+static void 
+beat_up(void)
+{
+  struct key_list *new = malloc(sizeof *new);
+  struct key_list **iter, *old_key = 0;
+  int key_count = 0;
+
+  if (new == 0) {
+    fprintf(stderr, "malloc failed\n");
+    abort();
+  }
+
+  new->next = 0;
+
+  if (pthread_key_create(&new->key, 0) != 0) {
+    fprintf(stderr, "pthread_key_create failed\n");
+    abort();
+  }
+
+  if (pthread_getspecific(new->key) != 0) {
+    fprintf(stderr, "new pthread_key_t resolves to non-null value\n");
+    abort();
+  }
+
+  pthread_setspecific(new->key, (void *) 1);
+
+#ifdef CHATTY
+  printf("created key\n");
+#endif
+
+  pthread_mutex_lock(&key_lock);
+
+  for (iter = &key_list; *iter != 0; iter = &(*iter)->next)
+    key_count++;
+
+  *iter = new;
+
+  if (key_count > max_keys) {
+    old_key = key_list;
+    key_list = key_list->next;
+  }
+
+  pthread_mutex_unlock(&key_lock);
+
+  if (old_key != 0) {
+#ifdef CHATTY
+    printf("deleting key\n");
+#endif
+    pthread_key_delete(old_key->key);
+  }
+}
+
+static void *
+thread(void *arg)
+{
+  int i;
+  for (i = 0; i < beatup_iterations; i++) 
+    beat_up();
+  return 0;
+}
+
+int
+main(void)
+{
+  int i;
+  pthread_attr_t detached_thread;
+
+  pthread_attr_init(&detached_thread);
+  pthread_attr_setdetachstate(&detached_thread, PTHREAD_CREATE_DETACHED);
+
+  for (i = 0; i < num_threads; i++) {
+    pthread_t thread_id;
+    while (pthread_create(&thread_id, &detached_thread, thread, 0) == EAGAIN) {
+      /* let some threads die, so system can breathe. :) */
+      sleep(1);
+    }
+  }
+
+  pthread_exit(0);
+}