<div class="meta" robots="noindex">

</div>

Class

# Xojo.Threading.Semaphore

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `Semaphore</api/language/threading/semaphore>` as a replacement.

</div>

## Description

Used to coordinate access to a shared resource.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                 | Parameters                                                                                | Returns                            | Shared |
|------------------------------------------------------|-------------------------------------------------------------------------------------------|------------------------------------|--------|
| `Constructor<xojo.threading.semaphore.constructor0>` | `Optional</api/language/optional>` numResources As `Integer</api/data_types/integer>` = 1 |                                    |        |
| `Release<xojo.threading.semaphore.release>`          |                                                                                           |                                    |        |
| `Signal<xojo.threading.semaphore.signal>`            |                                                                                           |                                    |        |
| `TrySignal<xojo.threading.semaphore.trysignal>`      |                                                                                           | `Boolean</api/data_types/boolean>` |        |

## Method descriptions

<div id="xojo.threading.semaphore.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Semaphore.Constructor

**Constructor**(`Optional</api/language/optional>` numResources As `Integer</api/data_types/integer>` = 1)

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

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

<div id="xojo.threading.semaphore.release">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Semaphore.Release

**Release**

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

<div id="xojo.threading.semaphore.signal">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

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.

<div id="xojo.threading.semaphore.trysignal">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Threading.Semaphore.TrySignal

**TrySignal** As `Boolean</api/data_types/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</api/data_types/additional_types/object>` parent class; `CriticalSection</api/language/threading/criticalsection>`, `Thread</api/language/threading/thread>` classes
