nasa / osal

The Core Flight System (cFS) Operating System Abstraction Layer (OSAL)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add abstraction for condition variables

jphickey opened this issue · comments

Is your feature request related to a problem? Please describe.
POSIX condition variables can be useful for implementing worker thread pools, allowing worker task(s) to pend for work and dispatcher/manager tasks to unblock those workers once a job becomes available.

Describe the solution you'd like
Abstraction of something like POSIX condition variables via OSAL APIs.

Describe alternatives you've considered
Some of the worker pool concepts may be implemented with simple semaphores, but those aren't ideal for some use cases:

  • a counting sem needs a 1:1 relationship between gives and takes, so it is not ideal for cases where work can be "batched" - either where a single input can unblock multiple worker jobs, or multiple inputs can be handled by a single worker job.
  • a binary sem helps the second case by capping the semaphore count at 1, such that multiple "gives" on the dispatch side only cause a single worker run. But it does not allow for a dispatcher to unblock multiple workers, nor can it act on other conditions than a simple boolean.

Note that in the POSIX OSAL the binary semaphore is, in fact, implemented using condition variables underneath - where the condition is just a single boolean value. But only this limited use-case is exposed/available to applications.

As a backward-compatible compromise of sorts - it may be possible to build on the current binary sem concept but allow the application to register its own "condition test" routine beyond the simple boolean.

Additional context
VxWorks support is not fully clear, I think VxWorks 7 has the underlying APIs to implement this, but 6.x might not.

Requester Info
Joseph Hickey, Vantage Systems, Inc.

Looking into doing this as bplib (for DTN) relies on condition variables for synchronization and it would benefit from having an OSAL API that provides this capability.