|
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/. */ |
|
5 |
|
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 |
|
16 |
|
17 #define THREADS 10 |
|
18 |
|
19 |
|
20 void |
|
21 threadmain(void *_id) |
|
22 { |
|
23 int id = (int)_id; |
|
24 int index; |
|
25 |
|
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); |
|
33 |
|
34 } |
|
35 |
|
36 int main(int argc, char **argv) |
|
37 { |
|
38 int index; |
|
39 PRThread *a[THREADS]; |
|
40 |
|
41 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 5); |
|
42 PR_STDIO_INIT(); |
|
43 |
|
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 } |