Fix: introduce memory barriers to prevent runtime reordering across lock ops.

These barriers already exist in the mutex implementation, but were omitted from
the semaphore. These translate to a memory barrier that prevents the processor
reordering operations across these points at runtime.