How do you handle synchronization and race conditions between a high-priority hardware interrupt and a background RTOS task?