3 ms·
We're deep in a ridiculous scenario here, but the answer is that, yes, this would result in a safe program, provided that it never calls malloc() from a signal
by akoboldfrying 3y ago
We're deep in a ridiculous scenario here, but the answer is that, yes, this would result in a safe program, provided that it never calls malloc() from a signal handler (since that would deadlock if the interrupted code had already grabbed the lock/mutex/semaphore/whatever).
In any other scenario, if some execution thread reaches the point where it returns from calling lock() on the mutex guarding malloc(), it must eventually reach the call to unlock().