!7 set flag LeanMode. set flag OurSyncCollections. set flag collectionMutex_simple. //do not include class Symbol. set flag SymbolAsString. //do not include function getOpt. sbool ping() { ret ping_v3(); } static new PingSource myPingSource; static double coresToUse = .5; static double frequency = 100; static new BoolVar on; static volatile long result; static NotTooOften nto = nto(1.0); p/*-exp*/ { // exp for "experiment" automatically reloads on updates new Schedule schedule; //enableScaffolding(schedule); schedule.add(0, r { dontprint("on"); myPingSource.action(null); on.set(); }); schedule.add(coresToUse, r { dontprint("off"); on.unset(); myPingSource.action(-> { temp tempPingPrivileged(); on.waitUntilTrue(); true; }); }); schedule.jumpFromTo(1, 0); schedule.speedUp(frequency); //printStruct(schedule); thread "Counting" { temp tempSetPingSource(myPingSource); new Timestamp start; long i = 0; var ping = pingSource(); while (true) { if (ping_trueIfSlept(ping)) { result = i; if (nto!) { Seconds cpu = new(nanosToSeconds(currentThreadTotalCPUNanos())); Seconds clock = new(elapsedSeconds(start)); double numbersPerSecond = doubleRatio(i, clock!); print("I have counted until " + n2(i) + ". pid=" + pid() + ", cpu time: " + cpu + " (clock: " + clock + ", ratio: " + formatDouble1(doublePercentRatio(cpu, clock)) + "%) - " + n2(ifloor(numbersPerSecond)) + " numbers per second"); } } ++i; } } schedule.run(); }