package threads; //| //| test of 11 threads running simultaneously //| 10 of them will cause garbage collection at one time //| and one will run constantly, even during garbage collection //| var all = new array(); var all_guard = new mutex(); // will cause garbage collection due to string allocations function thread_func(sign) { var i, x = ""; for (i = 0; i < 1000; ++i) { // will be suspended here during gc cycle // somewhere in the next statement x += " hello " + " goodbye "; // will be awakened after gc cycle print(sign); } print("*****"); synchronized(all_guard) { all[sign] = new thread(thread_func,sign); } } // will not cause garbage collection. nothing allocating // will be active even during gc cycle function nongc_thread_func() { var i,x = 0; for (i = 0; i < 1000; ++i) { x = x + 1; print("_"); } print("/////"); new thread(nongc_thread_func); } function main() { var i; for (i = 0; i < 10; ++i) all.push(new thread(thread_func,i)); new thread(nongc_thread_func); var w; do { w = 0; synchronized(all_guard) { for (i = 0; i < all.length; ++i) { if(all[i].running) w = 1; } } print("-"); } while(w); }