Synchronization in LabVIEW – Part 2

Synchronization in LabVIEW – Part 2

 

LabVIEW offers several types of synchronization tools. They can be placed into two groups.

  1. Occurrence, Notifier, and Queue
  2. Semaphore and Rendezvous

In Synchronization in LabVIEW – Part 1, group 1 was reviewed. This post covers group 2. As a short summary, the first group pauses execution of a piece of code until data is available or a condition is met. The second group manages access to a piece of code based on the actions of multiple data sources. For example, you may need to assure that the motion controller has reached the measurement position and the load on the material being measured has reached the right level. Once both of those items have happened, the measurement can occur.

Semaphores and Rendezvous

The final two sync tools force code to wait on an event, in contrast to data availability like the Notifier and Queue.

The Semaphore tools are found in the sync palette at ‘Programming> Synchronization > Semaphore’ and the Rendezvous tools are found at ‘Programming > Synchronization > Rendezvous’. The Semaphore palette is shown next.

Semaphore-Palette

The Semaphore has the following basic operations: Create, Acquire, Release, and Destroy. The Rendezvous has the following basic operations: Create, Wait, and Destroy.

A Semaphore acts like a 4-way stop sign: multiple sections of code want to go, but the stop signs only allow one car at a time. Some example uses are:

  • Multiple sections of code want access to a single device (e.g. a DAQ board).
  • Only allow one section of code access to a Notifier at a time.
  • A read\write data manager is not read until a write is completed (or vice versa).

A Rendezvous acts like the leader of a group: the entire group is held back until the leaders finds that everyone in the group is ready to move. Some example uses are:

  • Perform calculations only after all input channels have been acquired.
  • Move to the next position after all the motion controller axes are stopped moving.
  • Open all tank valves only after all tanks are filled as indicated by level sensors.

Some examples of these sync tools can be found with the NI Example Finder by using “semaphore” or “rendezvous” in the search tab. For example, the rendezvous example resides at <…\National Instruments\LabVIEW 8.5\examples\general\rendezvous.llb\Rendezvous with SubVIs.vi> and its diagram is shown below.

Rendezvous-Example-Block-Diagram

This example creates a Rendezvous of “group” size equal 3, starts three (User) VIs running in parallel, and destroys the Rendezvous after the ‘stop’ button is pressed. Each User VI executes a task which takes a random amount of time to complete. After the task is complete, the VI loops to get ready for another task.

Initially, all three User VIs run in parallel. When one completes prior to the rest, it waits for all others to complete. Only when all 3 tasks are completed, do any of them start their task again. Then, all 3 begin their next task simultaneously.

Semaphore and Rendezvous Options

These sync tools have the usual timeout and naming options. But, note that the naming option during calls to Create has a flag “return existing” that is different than the Notifier and Queue option of “Create if not found”. The meaning is the same, but the logic is reversed. Using TRUE for Notifier and Queue and FALSE for Semaphore and Rendezvous have the same effect.

These sync tools have an important difference from the Notifier and Queue tools: both have knowledge of the quantity of members. The Semaphore defaults to allowing access to 1 member only, but you can create a Semaphore that will release when there are N members waiting; N is specified at Create. Normal usage of a Rendezvous requires that all N members are available before the Rendezvous releases. As with the Semaphore, N is specified at Create. A Rendezvous can be resized after creation, Semaphores cannot.

2019-02-18T09:29:13+00:00