Class

Xojo.Threading.Semaphore


Warning

This item was deprecated in version 2020r2. Please use Semaphore as a replacement.

Description

Used to coordinate access to a shared resource.

Methods

Name

Parameters

Returns

Shared

Constructor

Optional numResources As Integer = 1

Release

Signal

TrySignal

Boolean

Method descriptions


Xojo.Threading.Semaphore.Constructor

Constructor(Optional numResources As Integer = 1)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a semaphore with an initial count of resources to track.


Xojo.Threading.Semaphore.Release

Release

Call Release to give a locked resource back to the Semaphore.


Xojo.Threading.Semaphore.Signal

Signal

Call Signal to obtain a lock on a resource, blocking until it does. Once you are done with the shared resource, call Release to decrement the internal counter.

Every time a thread calls Signal, the Semaphore decrements the counter. If the counter is less than zero, it suspends the thread.

When you obtain a lock, you can use the resource. If the call succeeds, this function returns immediately and you code continues to execute. If the lock is not available, then the thread that called this method will wait until the lock becomes available. When you are finished using the resource, call the Release method to give it back to the Semaphore.


Xojo.Threading.Semaphore.TrySignal

TrySignal As Boolean

Determines whether there is a lock available. If there is a lock available, you are granted the lock and TrySignal returns True. When you are finished with the resource, call Release to give it back to the Semaphore. If the lock is not available, it does not block. Instead, TrySignal returns False to let you know. Do not attempt to use the resource after it returns False because you are likely to collide with another thread.

Compatibility

All project types on all supported operating systems.

See also

Object parent class; CriticalSection, Thread classes