semSignal (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The semSignal() function will perform a traditional SIGNAL operation on the specified semaphore.

The semSignal() mechanism will:

If there are threads blocked in the semWait() waiting queue for the semaphore, the first thread will be released to execute.

Otherwise the semaphore value will be incremented by 1.

 

Also see the function semWait() and the section on thread synchronization for more information.

 

 

Input:

sem : SEMAPHORE

The semaphore to Signal.                

 

Returns: INT

0

Semaphore is signaled.

1

Semaphore is not initialized.

 

Declaration:

FUNCTION semSignal : INT;
VAR_INPUT
  sem : SEMAPHORE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  sem : SEMAPHORE;
END_VAR;
 
PROGRAM test;
  ...
  // Initialize Semaphore
  sem := semInit(initval:=3);
  IF semValue(sem:=sem) = -1 THEN DebugMsg(message:="sem failed to init!"); END_IF;
  ...
BEGIN
  ...
  // Wait until resource is free or timeout
  IF semWait(sem:=sem,timeout:=1000) = 0 THEN
    // Only do these actions if we have access to the resource
     ...
    // Free the resource after use
    semSignal(sem:=sem);
  END_IF;
  ...
END;
 
END_PROGRAM;