Armv8-A provides ldxr and stxr for exclusive access. You can either use compiler’s built-in function or hand written assembly. However, you need to enable MMU and data cache before using the ldxr instruction in real rpi3. So, you can now use a workaround such as disable preemption in real rpi3 or just give it a trial in QEMU which doesn’t have to enable MMU for ldxr.
Requirement
Implement mutex_lock, mutex_unlock. If task fail to acquire the lock, it would go to sleep and context switch to other tasks.