As far as I know the below code should result in a deadlock and NOT print out "hello world". However, when I compile on my computer (Macbook Air late 2013, 10.9.2) with gcc, the code unexpectedly prints "hello world" and finishes execution.
Why does the below code not result in deadlock?
#include <stdio.h>
#include <semaphore.h>
int main() {
sem_t prod_slots;
sem_init(&prod_slots, 0, 0);
sem_wait(&prod_slots);
sem_wait(&prod_slots);
sem_wait(&prod_slots);
printf("%s\n", "hello world");
return 1;
}