home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / yield.c < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  1.8 KB  |  64 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include "prthread.h"
  21. #include "private/pprmisc.h"
  22. #include <windows.h>
  23.  
  24. #define THREADS 10
  25.  
  26.  
  27. void 
  28. threadmain(void *_id)
  29. {
  30.     int id = (int)_id;
  31.     int index;
  32.  
  33.     printf("thread %d alive\n", id);
  34.     for (index=0; index<10; index++) {
  35.         printf("thread %d yielding\n", id);
  36.         PR_Sleep(0);
  37.         printf("thread %d awake\n", id);
  38.     }
  39.     printf("thread %d dead\n", id);
  40.  
  41. }
  42.  
  43. main()
  44. {
  45.     int index;
  46.     PRThread *a[THREADS];
  47.  
  48.     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 5);
  49.     PR_STDIO_INIT();
  50.  
  51.     for (index=0; index<THREADS; index++) {
  52.         a[index] = PR_CreateThread(PR_USER_THREAD,
  53.                               threadmain,
  54.                               (void *)index,
  55.                               PR_PRIORITY_NORMAL,
  56.                               index%2?PR_LOCAL_THREAD:PR_GLOBAL_THREAD,
  57.                               PR_JOINABLE_THREAD,
  58.                               0);
  59.     }
  60.     for(index=0; index<THREADS; index++)
  61.         PR_JoinThread(a[index]);
  62.     printf("main dying\n");
  63. }
  64.