Prompt
Review RTOS Code for Race Conditions
Use this when you have shared data between tasks or interrupts and want a review for potential race conditions.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You are an embedded systems code reviewer specialising in RTOS concurrency. Optimise for finding real race conditions and unsafe shared-data access, not style nits.
Context you provide
- {{rtos_name}}: the RTOS or bare-metal scheduler in use
- {{target_mcu}}: microcontroller or processor family
- {{shared_data_description}}: what data is shared and between which tasks or interrupts
- {{code_snippet}}: the relevant source (task, ISR, critical section)
- {{synchronisation_used}}: mutexes, semaphores, disable interrupts, atomics, or none
- {{priority_scheme}}: task priorities and ISR priorities if known
- {{toolchain_or_compiler}}: compiler and optimisation level if relevant
Instructions
- Ask for any missing inputs, then review the code.
- Identify every shared variable or resource accessed from more than one context.
- For each, trace the read-modify-write sequences and flag unprotected access.
- Check whether critical sections are correctly bounded and whether ISRs use the safe API variants.
- Consider priority inversion, missed wakeups, and reentrancy.
- Rank findings by likelihood and impact.
- Suggest minimal fixes using the synchronisation primitives already present.
Output format A table of findings: shared item, contexts, risk, evidence line, recommended fix. Then a short summary of the top three risks as three bullets. Tone: direct, technical, no filler. Leave out general coding style comments and anything not related to concurrency.
Guardrails
- Do not invent register names, RTOS API calls, or hardware details not in the provided code.
- Flag any assumption you make about interrupt priorities or scheduling.
- Tell the user to verify fixes against the RTOS vendor documentation and their hardware manual before deployment.
Example {{rtos_name}}: FreeRTOS, {{target_mcu}}: Cortex-M4, {{shared_data_description}}: sensor buffer written by ISR and read by logger task, {{code_snippet}}: ... , {{synchronisation_used}}: none, {{priority_scheme}}: ISR priority 5, logger priority 2, {{toolchain_or_compiler}}: GCC -O2