import element.*; public class SynchThread extends Thread { private static int ticker = 0; synchronized static public int count() // post: return a unique counter value { int result = ticker; yield(); ticker++; yield(); return result; } public void run() // post: print counter values until one larger than 10 is printed { int ticket; do { ticket = count(); System.out.println(ticket); } while (ticket < 10); } public static void main(String args[]) // post: run five threads that fight over the counter { int i; for (i = 0; i < 5; i++) { new SynchThread().start(); } } } /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */