c++ - pthread-win32 extension sem_post_multiple -
i building thin c++ wrapper around pthreads in-house use. windows qnx targeted , fortunately pthreads-win32 ports seems work well, while qnx conformant posix our practical purposes.
now, while implementing semaphores, hit function
sem_post_multiple(sem_t*, int) which apparently available on pthreads-win32 missing qnx. name suggests function supposed increment semaphore count given second argument. far can tell function not part of neither posix 1b nor posix 1c.
although there no requirement said function still wondering why pthreads-win32 provides function , whether might of use. try mimic qnx using similar following:
sem_post_multiple_qnx(sem_t* sem, int count) { for(;count > 0; --count) { sem_post(sem); } } what asking suggestion/advice on how proceed. if consensus suggests implement function qnx appreciate comments on whether suggested code snipped viable solution.
thanks in advance.
ps: deliberately left out fancy c++ class clarity. folks suggesting boost rescue: not option in current project due management reasons.
in case semaphores optional extension in posix. e.g os x doesn't seem implement them fully. if concerned portability, you'd have provide wrappers of functionalities need, anyhow.
your approach emulate atomic increment iterated sem_post has downsides.
- it might performing badly,
sem_tused in performance critical contexts. - this operation not atomic. confusing things might happen before finish loop.
i stick necessary, strictly posix conforming. beware sem_timedwait yet optional part of semaphore option.
Comments
Post a Comment