references thread ids modulo number of threads

* thread ids are assigned statically so not reset between tests or use of CASConsensus
bakery locking algorithm implementation

* needed to add synchronized block over shared variable because otherwise java might lose some updates probably due to JMM constraints
bakery lock test using side-effects