In PHP, how does the lock function differ from trylock in terms of waiting for other threads to release locks?

When using the `lock` function in PHP, the thread will wait indefinitely until it acquires the lock, potentially causing a deadlock if another thread never releases the lock. On the other hand, the `trylock` function will attempt to acquire the lock but will return immediately if it's not available, allowing the thread to continue execution without getting stuck. This can be useful in situations where waiting for a lock indefinitely is not desired.

// Using trylock to avoid deadlock
$mutex = Mutex::create();
if (Mutex::trylock($mutex)) {
    // Lock acquired successfully
    // Perform critical section code here
    Mutex::unlock($mutex);
} else {
    // Lock not acquired, handle accordingly
}
Mutex::destroy($mutex);