Ejemplo n.º 1
0
void PR_CALLBACK
Level_1_Thread(void *arg)
{
    PRUint32 tmp = (PRUint32)arg;
    PRThreadScope scope = (PRThreadScope) tmp;
    PRThread *thr;

    thr = PR_CreateThreadGCAble(PR_USER_THREAD,
        Level_2_Thread,
        NULL,
        PR_PRIORITY_HIGH,
        scope,
        PR_JOINABLE_THREAD,
        0);

    if (!thr) {
        printf("Could not create thread!\n");
    } else {
        printf("Level_1_Thread[0x%lx] created %15s thread 0x%lx\n",
            PR_GetCurrentThread(),
            (scope == PR_GLOBAL_THREAD) ?
            "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD",
            thr);
        PR_JoinThread(thr);
    }
    PR_EnterMonitor(mon);
    alive--;
    PR_Notify(mon);
    PR_ExitMonitor(mon);
    printf("Thread[0x%lx] exiting\n",PR_GetCurrentThread());
}
Ejemplo n.º 2
0
static int realMain(int argc, char **argv, char *notused) {
  int i;
  int threads = 0;

#ifndef XP_MAC
  progname = strrchr(argv[0], '/');
  if (progname == 0) progname = argv[0];
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-t") == 0) {
      if (i == argc - 1) {
	usage(progname);
      }
      threads = atoi(argv[++i]);
      if (threads < 0) threads = 0;
      if (threads > 10000) threads = 10000;
      continue;
    }
    if (strcmp(argv[i], "-l") == 0) {
      if (i == argc - 1) {
	usage(progname);
      }
      loops = atoi(argv[++i]);
      continue;
    }
    usage(progname);
  }
#else
	threads = 50;
#endif

  for (i = 0; i < threads; i++) {
    PRThread* thread;

    /* XXXXX */
    thread = PR_CreateThreadGCAble(PR_USER_THREAD,  /* thread type */
			     AllocStuff,  /* start function */
			     NULL,  /* arg */
			     PR_PRIORITY_NORMAL,  /* priority */
			     PR_LOCAL_THREAD,  /* thread scope */
			     PR_UNJOINABLE_THREAD,  /* thread state */
			     0);   /* stack size */
    if (thread == 0) {
#ifndef XP_MAC
      fprintf(stderr, "%s: no more threads (only %d were created)\n",
	      progname, i);
#else
      printf("%s: no more threads (only %d were created)\n",
	      progname, i);
#endif
      break;
    }
  }
  AllocStuff(NULL);
  return 0;
}
Ejemplo n.º 3
0
static void Level_0_Thread(PRThreadScope scope1, PRThreadScope scope2)
{
    PRThread *thr;
    PRThread *me = PR_GetCurrentThread();
    int n;
    PRInt32 words;
    PRWord *registers;

    alive = 0;
    mon = PR_NewMonitor();

    alive = count;
    for (n=0; n<count; n++) {
        thr = PR_CreateThreadGCAble(PR_USER_THREAD,
            Level_1_Thread, 
            (void *)scope2, 
            PR_PRIORITY_NORMAL,
            scope1,
            PR_UNJOINABLE_THREAD,
            0);
        if (!thr) {
            printf("Could not create thread!\n");
            alive--;
        }
        printf("Level_0_Thread[0x%lx] created %15s thread 0x%lx\n",
            PR_GetCurrentThread(),
            (scope1 == PR_GLOBAL_THREAD) ?
            "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD",
            thr);

        PR_Sleep(0);
    }
    PR_SuspendAll();
    PR_EnumerateThreads(print_thread, NULL);
    registers = PR_GetGCRegisters(me, 1, (int *)&words);
    if (registers)
        printf("My Registers: R0 = 0x%x R1 = 0x%x R2 = 0x%x R3 = 0x%x\n",
            registers[0],registers[1],registers[2],registers[3]);
    printf("My Stack Pointer = 0x%lx\n", PR_GetSP(me));
    PR_ResumeAll();

    /* Wait for all threads to exit */
    PR_EnterMonitor(mon);
    while (alive) {
        PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
    }

    PR_ExitMonitor(mon);
    PR_DestroyMonitor(mon);
}