Friday, April 2, 2010

Java locks vs. POSIX locks

A few days ago I spent some time comparing Java synchronization primitives and those from POSIX thread library and found some differences from both the default behaviour and the terminology point of view.

Fist of all, java intrinsic locks are reentrant. It means that thread that already holds a lock can acquire the same lock. Without that property the thread would block when reacquiring the lock it already holds. POSIX locks ( or mutex variables) are not reentrant (of recursive) by default but can become reentant if properly configured.