added a static counter, just for printing. WARNING -- expected undefined behaviour with multithreaded code.