well, it mostly depends on what “rest of code” does. If that’s a predictably bound computation, you can simply create a FreeRTOS timer that checks the flag and executes “rest of code” if flags is != 1. If that is a lengthy computation, however, you can employ a variation of your scheme, namely, a task that is normally suspended and woken via vTaskResume() by your timer routine if the flag is != 1. That’s fairly off-the-shelf-code.