8.2 Semaphore Object

The entry point to Semaphore properties and methods.

8.2.1 Global property

Sets or determines whether or not the semaphore is global.

Syntax

object.Global[=Sem As Boolean]

Type

Boolean.

Attributes

Read/write.

Remarks

Sem is an optional parameter that specifies a global (TRUE) or local (FALSE) semaphore.

Example

This example sets the semaphore as Global.

set Sem = CreateObject("ucx:Semaphore") 
print(Sem.Global) 
Sem.Global=True

See Also

8.2.2 ID property

Sets or returns the semaphore ID.

Syntax

object.ID[=SemID As Long]

Type

Long.

Attributes

Read/write.

Remarks

SemID is an optional parameter. For a local semaphore, you can use it to set the Semaphore ID to 1-5. For a global semaphore, it is read-only.

Example

This example returns the semaphore ID.

set Sem = CreateObject("ucx:Semaphore") 
Sem.global=True 
sem.name="YY" 
sem.lock(10) 
print("Semaphore ID is: " &sem.ID) 
sem.unlock

See Also

8.2.3 Locked property

Determines whether or not the semaphore is locked.

Syntax

object.Locked

Type

Boolean.

Attributes

Read-only.

Remarks

This property returns TRUE if the semaphore is locked; otherwise; FALSE.

Example

This example returns TRUE if the semaphore is locked; otherwise, FALSE.

set Sem = CreateObject("ucx:Semaphore") 
Sem.global=True 
sem.name="YY" 
sem.lock(10) 
if sem.Locked = True Then 
     print "True" 
else 
     print "False" 
end if 
sem.Unlock

8.2.4 Name property

Sets or returns the semaphore name.

Syntax

object.Name[=Name As String]

Type

String.

Attributes

Read/write.

Remarks

Name is an optional parameter that represents the new name of the semaphore.

Example

This example returns the name of the semaphore.

set sem = CreateObject("ucx:Semaphore") 
Sem.global=True 
sem.name="YY" 
sem.lock(10) 
print("Semaphore name is: " &sem.Name) 
sem.unlock

See Also

8.2.5 Lock method

Locks a semaphore.

Syntax

object.Lock(
   [Timeout As Integer])

Parameters

Timeout

Optional. The time, in milliseconds, to lock the semaphore. This parameter is required for a global semaphore, but not for a local semaphore.

Return Values

Boolean. Returns TRUE if the semaphore is successfully locked; otherwise, FALSE.

Example

This example locks the YY semaphore in 1000 milliseconds.

set sem = CreateObject("ucx:Semaphore") 
Sem.global=True 
sem.name="YY" 
sem.lock(10) 
     if (Sem.Global=True) Then 
          Sem.Lock(1000) 
          print "Global semaphore is locked" 
     else 
          Sem.Lock() 
          print "Local semaphore is locked" 
     end if 
Sem.Unlock()

8.2.6 Unlock method

Unlocks a semaphore.

Syntax

object.Unlock()

Parameters

None.

Return Values

Boolean. Returns TRUE if the semaphore is successfully unlocked; otherwise, FALSE.

Example

This example unlocks the YY semaphore.

set sem = CreateObject("ucx:Semaphore") 
Sem.global=True 
sem.name="YY" 
sem.lock(10) 
     if (Sem.Global=True) Then 
          Sem.Lock(1000) 
          print "Global semaphore is locked" 
     else 
          Sem.Lock() 
          print "Local semaphore is locked" 
     end if 
Sem.Unlock()