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.22 PTH_1_0b7:1.22 PTH_1_0b6:1.22 PTH_1_0b5:1.22 PTH_1_0b4:1.21 PTH_1_0b3:1.19 PTH_1_0b2:1.19 PTH_1_0b1:1.18 PTH_0_9_21:1.17 PTH_0_9_20:1.15 PTH_0_9_19:1.14 PTH_0_9_18:1.11 PTH_0_9_17:1.11 PTH_0_9_16:1.11 PTH_0_9_15:1.11 PTH_0_9_14:1.11 PTH_0_9_13:1.9 PTH_0_9_12:1.8 PTH_0_9_11:1.8 PTH_0_9_10:1.8 PTH_0_9_9:1.8 PTH_0_9_8:1.8 PTH_0_9_7:1.5 PTH_0_9_6:1.5 PTH_0_9_5:1.4 PTH_0_9_4:1.4 PTH_0_9_3:1.4 PTH_0_9_2:1.4 PTH_0_9_1:1.1.1.1 PTH_0_9_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @ * @; 1.38 date 2007.01.01.18.23.53; author rse; state Exp; branches; next 1.37; commitid 9DhdiirNzQPBIP0s; 1.37 date 2006.06.08.17.54.54; author rse; state Exp; branches; next 1.36; commitid x8N3mLVdQgkbdeAr; 1.36 date 2004.12.31.19.34.45; author rse; state Exp; branches; next 1.35; 1.35 date 2004.07.13.10.50.49; author rse; state Exp; branches; next 1.34; 1.34 date 2003.01.01.15.49.12; author rse; state Exp; branches; next 1.33; 1.33 date 2002.01.27.11.03.41; author rse; state Exp; branches; next 1.32; 1.32 date 2001.03.24.14.51.05; author rse; state Exp; branches; next 1.31; 1.31 date 2000.02.24.12.35.01; author rse; state Exp; branches; next 1.30; 1.30 date 99.12.30.21.59.02; author rse; state Exp; branches; next 1.29; 1.29 date 99.11.09.08.11.32; author rse; state Exp; branches; next 1.28; 1.28 date 99.11.01.19.03.49; author rse; state Exp; branches; next 1.27; 1.27 date 99.11.01.10.27.21; author rse; state Exp; branches; next 1.26; 1.26 date 99.10.31.11.46.14; author rse; state Exp; branches 1.26.2.1; next 1.25; 1.25 date 99.09.17.08.01.56; author rse; state Exp; branches; next 1.24; 1.24 date 99.08.17.08.08.36; author rse; state Exp; branches; next 1.23; 1.23 date 99.08.03.12.24.03; author rse; state Exp; branches; next 1.22; 1.22 date 99.07.10.14.21.18; author rse; state Exp; branches; next 1.21; 1.21 date 99.07.08.10.34.02; author rse; state Exp; branches; next 1.20; 1.20 date 99.07.08.10.19.12; author rse; state Exp; branches; next 1.19; 1.19 date 99.07.04.12.05.36; author rse; state Exp; branches; next 1.18; 1.18 date 99.06.27.15.38.04; author rse; state Exp; branches; next 1.17; 1.17 date 99.06.26.12.54.17; author rse; state Exp; branches; next 1.16; 1.16 date 99.06.26.12.51.27; author rse; state Exp; branches; next 1.15; 1.15 date 99.06.24.11.25.07; author rse; state Exp; branches; next 1.14; 1.14 date 99.06.21.15.24.04; author rse; state Exp; branches; next 1.13; 1.13 date 99.06.21.10.07.29; author rse; state Exp; branches; next 1.12; 1.12 date 99.06.21.09.51.57; author rse; state Exp; branches; next 1.11; 1.11 date 99.06.01.15.51.33; author rse; state Exp; branches; next 1.10; 1.10 date 99.06.01.14.36.33; author rse; state Exp; branches; next 1.9; 1.9 date 99.06.01.09.55.27; author rse; state Exp; branches; next 1.8; 1.8 date 99.05.24.10.07.45; author rse; state Exp; branches; next 1.7; 1.7 date 99.05.24.07.58.14; author rse; state Exp; branches; next 1.6; 1.6 date 99.05.24.07.28.00; author rse; state Exp; branches; next 1.5; 1.5 date 99.05.22.14.37.53; author rse; state Exp; branches; next 1.4; 1.4 date 99.05.14.15.05.05; author rse; state Exp; branches; next 1.3; 1.3 date 99.05.14.13.43.31; author rse; state Exp; branches; next 1.2; 1.2 date 99.05.14.09.40.05; author rse; state Exp; branches; next 1.1; 1.1 date 99.05.13.12.18.16; author rse; state Exp; branches 1.1.1.1; next ; 1.26.2.1 date 99.11.01.10.25.03; author rse; state Exp; branches; next ; 1.1.1.1 date 99.05.13.12.18.16; author rse; state Exp; branches; next ; desc @@ 1.38 log @Adjusted all copyright messages for new year 2007. @ text @/* ** GNU Pth - The GNU Portable Threads ** Copyright (c) 1999-2007 Ralf S. Engelschall ** ** This file is part of GNU Pth, a non-preemptive thread scheduling ** library which can be found at http://www.gnu.org/software/pth/. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License as published by the Free Software Foundation; either ** version 2.1 of the License, or (at your option) any later version. ** ** This library is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** Lesser General Public License for more details. ** ** You should have received a copy of the GNU Lesser General Public ** License along with this library; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ** USA, or contact Ralf S. Engelschall . ** ** test_misc.c: Pth test program (misc functions) */ /* ``Study it forever and you'll still wonder. Fly it once and you'll know.'' -- Henry Spencer */ #include #include #include #include "pth.h" pth_mutex_t mutex = PTH_MUTEX_INIT; static void *my_reader(void *_arg) { char buf[3]; int n; for (;;) { n = pth_read(STDIN_FILENO, buf, 1); if (n < 0) { fprintf(stderr, "reader: error\n"); break; } if (n == 0) { fprintf(stderr, "reader: EOF\n"); break; } if (n == 1 && buf[0] == '\n') { buf[0] = '\\'; buf[1] = 'n'; n = 2; } buf[n] = NUL; fprintf(stderr, "reader: bytes=%d, char='%s'\n", n, buf); if (buf[0] == 'Q' || buf[0] == 'q') break; if (buf[0] == 'L' || buf[0] == 'l') { fprintf(stderr, "reader: ACQUIRE MUTEX\n"); pth_mutex_acquire(&mutex, FALSE, NULL); } if (buf[0] == 'U' || buf[0] == 'u') { fprintf(stderr, "reader: RELEASE MUTEX\n"); pth_mutex_release(&mutex); } fflush(stderr); } return NULL; } static void *my_child(void *_arg) { int i; char *name = (char *)_arg; for (i = 0; i < 10; ++i) { pth_mutex_acquire(&mutex, FALSE, NULL); fprintf(stderr, "%s: %d\n", name, i); pth_mutex_release(&mutex); pth_usleep(500000); } return NULL; } int main(int argc, char *argv[]) { pth_t child[10]; pth_attr_t t_attr; pth_attr_t t_attr2; long n; pth_init(); fprintf(stderr, "This is TEST_MISC, a Pth test using various stuff.\n"); fprintf(stderr, "\n"); fprintf(stderr, "A stdin reader child and various looping childs are\n"); fprintf(stderr, "spawned. When you enter 'l' you can lock a mutex which\n"); fprintf(stderr, "blocks the looping childs. 'u' unlocks this mutex.\n"); fprintf(stderr, "Enter 'q' to quit.\n"); fprintf(stderr, "\n"); fprintf(stderr, "Main Startup (%ld total threads running)\n", pth_ctrl(PTH_CTRL_GETTHREADS)); t_attr = pth_attr_new(); pth_attr_set(t_attr, PTH_ATTR_JOINABLE, FALSE); pth_attr_set(t_attr, PTH_ATTR_NAME, "foo"); child[0] = pth_spawn(t_attr, my_child, (void *)"foo"); pth_attr_set(t_attr, PTH_ATTR_NAME, "bar"); child[1] = pth_spawn(t_attr, my_child, (void *)"bar"); pth_attr_set(t_attr, PTH_ATTR_NAME, "baz"); child[2] = pth_spawn(t_attr, my_child, (void *)"baz"); pth_attr_set(t_attr, PTH_ATTR_NAME, "quux"); child[3] = pth_spawn(t_attr, my_child, (void *)"quux"); pth_attr_set(t_attr, PTH_ATTR_NAME, "killer"); pth_attr_set(t_attr, PTH_ATTR_PRIO, 4); child[4] = pth_spawn(t_attr, my_child, (void *)"killer"); pth_attr_set(t_attr, PTH_ATTR_NAME, "killer II"); pth_attr_set(t_attr, PTH_ATTR_PRIO, 5); child[5] = pth_spawn(t_attr, my_child, (void *)"killer II"); pth_attr_set(t_attr, PTH_ATTR_NAME, "reader"); pth_attr_set(t_attr, PTH_ATTR_PRIO, PTH_PRIO_STD); child[6] = pth_spawn(t_attr, my_reader, (void *)"reader"); pth_attr_destroy(t_attr); t_attr2 = pth_attr_of(child[0]); pth_attr_set(t_attr2, PTH_ATTR_PRIO, -1); pth_attr_destroy(t_attr2); t_attr2 = pth_attr_of(child[3]); pth_attr_set(t_attr2, PTH_ATTR_PRIO, +1); pth_attr_destroy(t_attr2); fprintf(stderr, "Main Loop (%ld total threads running)\n", pth_ctrl(PTH_CTRL_GETTHREADS)); while ((n = pth_ctrl(PTH_CTRL_GETTHREADS)) > 1) { fprintf(stderr, "Main Loop (%ld total threads still running)\n", n); pth_usleep(500000); } fprintf(stderr, "Main Exit (%ld total threads running)\n", pth_ctrl(PTH_CTRL_GETTHREADS)); pth_kill(); return 0; } @ 1.37 log @Adjusted all copyright messages for new year 2006 @ text @d3 1 a3 1 ** Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.36 log @Adjusted all copyright messages for new year 2005. @ text @d3 1 a3 1 ** Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.35 log @Adjusted all copyright messages for new year 2004. @ text @d3 1 a3 1 ** Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.34 log @Adjusted all copyright messages for new year 2003. @ text @d3 1 a3 1 ** Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.33 log @bump copyright year @ text @d3 1 a3 1 ** Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.32 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.31 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.30 log @*** empty log message *** @ text @d41 1 a41 1 while (1) { @ 1.29 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999 Ralf S. Engelschall @ 1.28 log @*** empty log message *** @ text @d87 1 a87 1 int main(int argc, char *argv[]) @ 1.27 log @*** empty log message *** @ text @d25 3 a27 1 @ 1.26 log @*** empty log message *** @ text @d2 1 a2 2 ** test_misc.c -- Pth test program (misc functions) ** d22 2 @ 1.26.2.1 log @*** empty log message *** @ text @d2 2 a3 1 ** GNU Pth - The GNU Portable Threads a22 2 ** ** test_misc.c: Pth test program (misc functions) @ 1.25 log @*** empty log message *** @ text @d12 1 a12 1 ** version 2 of the License, or (at your option) any later version. @ 1.24 log @*** empty log message *** @ text @d10 1 a10 1 ** modify it under the terms of the GNU Library General Public d17 1 a17 1 ** Library General Public License for more details. d19 1 a19 1 ** You should have received a copy of the GNU Library General Public @ 1.23 log @*** empty log message *** @ text @d106 1 a106 1 child[0] = pth_spawn(t_attr, my_child, "foo"); d108 1 a108 1 child[1] = pth_spawn(t_attr, my_child, "bar"); d110 1 a110 1 child[2] = pth_spawn(t_attr, my_child, "baz"); d112 1 a112 1 child[3] = pth_spawn(t_attr, my_child, "quux"); d115 1 a115 1 child[4] = pth_spawn(t_attr, my_child, "killer"); d118 1 a118 1 child[5] = pth_spawn(t_attr, my_child, "killer II"); d121 1 a121 1 child[6] = pth_spawn(t_attr, my_reader, "reader"); @ 1.22 log @*** empty log message *** @ text @a101 1 pth_nonblocking(STDIN_FILENO); @ 1.21 log @*** empty log message *** @ text @d91 2 a100 1 pth_init(); a102 1 @ 1.20 log @*** empty log message *** @ text @d2 1 a2 1 ** test_misc.c -- PTH test program (misc functions) d91 1 a91 1 fprintf(stderr, "This is TEST_MISC, a PTH test using various stuff.\n"); @ 1.19 log @*** empty log message *** @ text @d6 2 a7 2 ** This file is part of PTH, a non-preemptive thread scheduling library ** which can be found at http://www.gnu.org/software/pth/. @ 1.18 log @*** empty log message *** @ text @d7 1 a7 1 ** which can be found at http://www.engelschall.com/sw/pth/. @ 1.17 log @*** empty log message *** @ text @d88 1 a102 4 t_attr.at_prio = PTH_PRIO_STD; t_attr.at_flags = PTH_FLAG_NOJOIN; t_attr.at_stacksize = 32*1024; t_attr.at_stackaddr = NULL; d104 27 a130 19 t_attr.at_name = "foo"; child[0] = pth_spawn(&t_attr, my_child, "foo"); t_attr.at_name = "bar"; child[1] = pth_spawn(&t_attr, my_child, "bar"); t_attr.at_name = "baz"; child[2] = pth_spawn(&t_attr, my_child, "baz"); t_attr.at_name = "quux"; child[3] = pth_spawn(&t_attr, my_child, "quux"); pth_priority(child[0], -1); pth_priority(child[3], 1); t_attr.at_name = "killer"; child[4] = pth_spawn(&t_attr, my_child, "killer"); pth_priority(child[4], 2); t_attr.at_name = "killer II"; child[5] = pth_spawn(&t_attr, my_child, "killer II"); pth_priority(child[5], 5); t_attr.at_name = "reader"; child[6] = pth_spawn(&t_attr, my_reader, "reader"); pth_priority(child[6], 0); @ 1.16 log @*** empty log message *** @ text @d102 4 a105 4 t_attr.prio = PTH_PRIO_STD; t_attr.flags = PTH_FLAG_NOJOIN; t_attr.stacksize = 32*1024; t_attr.stackaddr = NULL; d107 1 a107 1 t_attr.name = "foo"; d109 1 a109 1 t_attr.name = "bar"; d111 1 a111 1 t_attr.name = "baz"; d113 1 a113 1 t_attr.name = "quux"; d117 1 a117 1 t_attr.name = "killer"; d120 1 a120 1 t_attr.name = "killer II"; d123 1 a123 1 t_attr.name = "reader"; @ 1.15 log @*** empty log message *** @ text @d31 1 a31 1 pth_mutex_t mutex = PTH_MUTEX_INITIALIZER; @ 1.14 log @*** empty log message *** @ text @d59 1 a59 1 pth_mutex_acquire(&mutex, NULL); d76 1 a76 1 pth_mutex_acquire(&mutex, NULL); @ 1.13 log @*** empty log message *** @ text @d59 1 a59 1 pth_mutex_acquire(&mutex, FALSE, NULL); d76 1 a76 1 pth_mutex_acquire(&mutex, FALSE, NULL); @ 1.12 log @*** empty log message *** @ text @d59 1 a59 1 pth_mutex_lock(&mutex, FALSE, NULL); d63 1 a63 1 pth_mutex_unlock(&mutex); d76 1 a76 1 pth_mutex_lock(&mutex, FALSE, NULL); d78 1 a78 1 pth_mutex_unlock(&mutex); @ 1.11 log @*** empty log message *** @ text @d31 2 d57 8 d76 1 d78 1 d89 8 @ 1.10 log @*** empty log message *** @ text @d82 4 a85 3 t_attr.prio = 0; t_attr.flags = PTH_FLAG_NOJOIN; t_attr.stacksize = 16*1024; @ 1.9 log @*** empty log message *** @ text @d51 1 a51 1 buf[n] = '\0'; @ 1.8 log @*** empty log message *** @ text @d20 1 a20 1 ** License along with this library; if not, write to the Free @ 1.7 log @*** empty log message *** @ text @d83 1 a83 1 t_attr.flags = 0; a84 1 t_attr.joinable = FALSE; @ 1.6 log @*** empty log message *** @ text @d6 1 a6 1 ** This file is part of PTH, a non-preemtive thread scheduling library @ 1.5 log @*** empty log message *** @ text @d76 1 a76 1 int n; d79 1 a79 1 fprintf(stderr, "Main Startup (%d total threads running)\n", pth_stat(PTH_STAT_TOTAL)); d107 1 a107 1 fprintf(stderr, "Main Loop (%d total threads running)\n", pth_stat(PTH_STAT_TOTAL)); d109 2 a110 2 while ((n = pth_stat(PTH_STAT_TOTAL)) > 1) { fprintf(stderr, "Main Loop (%d total threads still running)\n", n); d113 1 a113 1 fprintf(stderr, "Main Exit (%d total threads running)\n", pth_stat(PTH_STAT_TOTAL)); @ 1.4 log @*** empty log message *** @ text @d2 21 a22 2 ** test_misc -- just a little PTH testing application ** Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. @ 1.3 log @*** empty log message *** @ text @d1 4 d56 1 a56 1 pth_attr_t t_attr; @ 1.2 log @*** empty log message *** @ text @d80 1 @ 1.1 log @Initial revision @ text @d3 3 d14 1 a14 1 n = pth_read(0, buf, 1); d44 1 a44 1 pth_sleep(pth_time(0, 500000)); d57 1 d87 1 a87 1 pth_sleep(pth_time(0, 500000)); @ 1.1.1.1 log @Import of PTH into CVS @ text @@