Should a delay be expected to cause deadlock? I have made a simple program using the int main() {} function. It has a delay in it. It is evident the code before the delay is running, but the delay never seems to time out and let the next instructions through. Is this by design?

If I rename the method and call it exactly once from the loop() {} function though, it does work.

Edit:

The code borrowed the 'main()' function and I suppose redefined it:

int main() { 
    Forward();
    delay(3000);
    Reverse();
}

void Forward() {
    //...
}

void Reverse() {
    //... 
}


I can see this redefinition of main() could cause some serious issues based on the answer below.
You don't seem to use standard Arduino stuff since you defined your own main() which is normally avoided when programming Arduino.

If you take a look at Arduino provided main() (in hardware/cores/arduino/main.cpp), you'll see how it is defined:

#include &lt;Arduino.h&gt;

int main(void)
{
    init();

#if defined(USBCON)
    USBDevice.attach();
#endif

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

    return 0;
}


Did you notice the init() function call at the beginning?

Its code is defined in hardware/cores/arduino/wiring.c; what it does is setup all timers used by Arduino functions, in particular a timer that is needed by delay().

In the same wiring.c file, you can also find the definition of delay():

void delay(unsigned long ms)
{
    uint16_t start = (uint16_t)micros();

    while (ms &gt; 0) {
        if (((uint16_t)micros() - start) &gt;= 1000) {
            ms--;
            start += 1000;
        }
    }
}


This will turn into an infinite loop if micros() always return the same value, and it does so if init() has never been called before.

This is what happens with your code.