The SyncMutex class

(PECL sync >= 1.0.0)

Introduction

A cross-platform, native implementation of named and unnamed countable mutex objects.

A mutex is a mutual exclusion object that restricts access to a shared resource (e.g. a file) to a single instance.
Countable mutexes acquire the mutex a single time and internally track the number of times the mutex is locked.
The mutex is unlocked as soon as it goes out of scope or is unlocked the same number of times that it was locked.