nsprpub/pr/tests/yield.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial