IBM Support

Semaphore implementation in IBM Rational Rhapsody

Question & Answer


Question

How to implement 'Semaphore' in Rational Rhapsody?

Answer

A Semaphore is a synchronization device that allows a limited number of threads in one or more processes to access a resource.The semaphore maintains a count of the number of threads currently accessing the resource. Semaphores are useful in controlling access to a shared resource that can support only a limited number of users. The current count of the semaphore is the number of additional users allowed.

Rhapsody's framework defines OSAL classes that can be used to implement semaphore. For RiC it is the 'RiCOSSemaphore' class and for RiCpp it is the 'OMOSSemaphore' class. Both the classes have the various functions with respect to handling a semaphore.The two functions that guard the access to the semaphore are:

  • signal() - Releases a semaphore token
  • wait() - Obtains a semaphore token

Sample usage of the above functions:



    RiCOSSemaphore_wait(semaphore object, timeout);

    <<resource handling code>>

    RiCOSSemaphore_signal(semaphore object);


More information on the framework classes can be found in the framework guide (<installdir>/doc/help/framework.pdf)

Attached is a RiC project showing a sample implementation of semaphore.

In the semaphore example, there are three active classes accessing a semaphore. In this case, the maximum number of users who can access the semaphore at a given time is 48. Once the maximum allowed limit is reached, all further requests to access the semaphore is placed in a queue. These queued up requests are addressed as and when locked tokens are released.In this example, during the wait call, a user locks a semaphore token for 1000 system ticks, which can be increased or decreases. A value of -1 for the system tick would mean an indefinite wait.


Project_Semaphore_RiC.zip

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.5","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21398185