Altera_Forum
Honored Contributor
14 years agoInterprocess Locking / Atomic Operations Issue
I'm running MMU linux on a Nios2 core. I have a system running many applications accessing a shared memory space.
For synchronization, I'm using sem_open, sem_post, sem_wait calls. However, my applications were crashing because multiple threads/processes somehow all thought they had the lock at the same time.... After a lot of digging and debugging, I found that glibc implementation of these functions relies on atomic operations in userspace. Since there is no architecture support for atomic test-and-set-like operations, it falls back to non-atomic operations implemented in C (glibc/bits/atomic.h). Has anyone successfully used an interprocess locking mechanism from userspace? I've tried these semaphore operators along with pthread_mutex objects in shared memory space, but none are without flaws. Is there any fallback that I have? Even Linux's futex() relies on user-space atomic operations on a shared counter...