rem: while (counterRun) { Ns_SemaWait(&counterSema); if (counterRun) { while (keepCounting) { Counter++;
add: double d; int max;  if (argc > 2) { Tcl_AppendResult(interp, argv[0], ": wrong number args: should be \"", argv[0], " ?maximum?\"", (char *) NULL); return TCL_ERROR; } if (argc == 2) { if (Tcl_GetInt(interp, argv[1], &max) != TCL_OK) { return TCL_ERROR; } else if (max <= 0) { Tcl_AppendResult(interp, "invalid max \"", argv[1], "\": must be > 0", NULL); return TCL_ERROR; } } d = Ns_DRand(); if (argc == 1) { Tcl_PrintDouble(interp, d, interp->result); } else { sprintf(interp->result, "%d", (int) (d * max)); } return TCL_OK; }      double Ns_DRand(void) { static int initialized;  if (!initialized) { Ns_CsEnter(&lock); if (!initialized) { unsigned long seed; Ns_GenSeeds(&seed, 1); #ifdef HAVE_RAND48 srand48(seed); #elif defined(HAVE_RANDOM) srandom((unsigned int) seed); #else srand((unsigned int) seed); #endif initialized = 1; } Ns_CsLeave(&lock); } #if HAVE_RAND48 return drand48(); #elif HAVE_RANDOM return ((double) random() / (LONG_MAX + 1.0)); #else return ((double) rand() / (RAND_MAX + 1.0)); #endif }      void Ns_GenSeeds(unsigned long *seedsPtr, int nseeds) { Ns_Thread thr;  Ns_CsEnter(&lock); Ns_SemaInit(&sema, 0); fRun = 1; Ns_ThreadCreate(CounterThread, NULL, 0, &thr); while (nseeds-- > 0) { *seedsPtr++ = TrueRand(); } fRun = 0; Ns_SemaPost(&sema, 1); Ns_ThreadJoin(&thr, NULL); Ns_SemaDestroy(&sema); Ns_CsLeave(&lock); }    static void CounterThread(void *ignored) { while (fRun) { Ns_SemaWait(&sema); if (fRun) { while (fCount) { counter++;
context: CounterThread(void){    while (counterRun) {        Ns_SemaWait(&counterSema);        if (counterRun) {	    while (keepCounting) {		Counter++;            }        }    }}