nsprpub/pr/tests/yield.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include <stdio.h>
     7 #include "prthread.h"
     8 #include "prinit.h"
     9 #ifndef XP_OS2
    10 #include "private/pprmisc.h"
    11 #include <windows.h>
    12 #else
    13 #include "primpl.h"
    14 #include <os2.h>
    15 #endif
    17 #define THREADS 10
    20 void 
    21 threadmain(void *_id)
    22 {
    23     int id = (int)_id;
    24     int index;
    26     printf("thread %d alive\n", id);
    27     for (index=0; index<10; index++) {
    28         printf("thread %d yielding\n", id);
    29         PR_Sleep(0);
    30         printf("thread %d awake\n", id);
    31     }
    32     printf("thread %d dead\n", id);
    34 }
    36 int main(int argc, char **argv)
    37 {
    38     int index;
    39     PRThread *a[THREADS];
    41     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 5);
    42     PR_STDIO_INIT();
    44     for (index=0; index<THREADS; index++) {
    45         a[index] = PR_CreateThread(PR_USER_THREAD,
    46                               threadmain,
    47                               (void *)index,
    48                               PR_PRIORITY_NORMAL,
    49                               index%2?PR_LOCAL_THREAD:PR_GLOBAL_THREAD,
    50                               PR_JOINABLE_THREAD,
    51                               0);
    52     }
    53     for(index=0; index<THREADS; index++)
    54         PR_JoinThread(a[index]);
    55     printf("main dying\n");
    56 }

mercurial