I’m working on a program with critical sections, so I am using semaphores. Specifically, the POSIX semaphores: http://www.kernel.org/doc/man-pages/online/pages/man3/sem_close.3.html
According to http://www.sbin.org/doc/glibc/libc_34.html (search: macro SEM_VALUE_MAX ), there is a maximum value that the general semaphore can be set to. On my system, this is about 32K.
Unfortunately, I’m dealing with some time-sensitive code (reading form an arduino via a serial port at ~1MBit/s), so I’d like to have larger semaphores, because of some implementation details. Ideally, I’d like them to be able to be at least 2^20, but I’m a little unclear on why there is an upper limit anyway.
Is there any way to exceed this SEM_VALUE_MAX, and get a semaphore with a larger value? I could only think of:
- Redefining SEM_VALUE_MAX
- probably a horrible idea; I think those POSIX folks know what they’re doing
- Having a semaphore refer to more than one ‘chunk’ of data
- right now, each up() or down() only acquires/releases a single ‘chunk’ — an unsigned short int.
- I imagine dealing with multiple at a time could cause deadlock.
- Implementing my own semaphores.
- time consuming / redundant work
- less portable
- Ask you wonderful folks what you think!
Thanks a bunch in advance!
Couldn’t you just use the semaphore to protect access to another counter that you use to track the allocations. That way you don’t need any more semaphore values than you have accessors.