0.2.0-dev Download ZIP
38 lines ·1.9 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="Semaphore" inherits="RefCounted" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A synchronization mechanism used to control access to a shared resource by [Thread]s. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | A synchronization semaphore that can be used to synchronize multiple [Thread]s. Initialized to zero on creation. For a binary version, see [Mutex]. |
| 8 | [b]Warning:[/b] Semaphores must be used carefully to avoid deadlocks. |
| 9 | [b]Warning:[/b] To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met: |
| 10 | - When a [Semaphore]'s reference count reaches zero and it is therefore destroyed, no threads must be waiting on it. |
| 11 | - When a [Thread]'s reference count reaches zero and it is therefore destroyed, it must not be waiting on any semaphore. |
| 12 | </description> |
| 13 | <tutorials> |
| 14 | <link title="Using multiple threads">$DOCS_URL/tutorials/performance/using_multiple_threads.html</link> |
| 15 | <link title="Thread-safe APIs">$DOCS_URL/tutorials/performance/thread_safe_apis.html</link> |
| 16 | </tutorials> |
| 17 | <methods> |
| 18 | <method name="post"> |
| 19 | <return type="void" /> |
| 20 | <param index="0" name="count" type="int" default="1" /> |
| 21 | <description> |
| 22 | Lowers the [Semaphore], allowing one thread in, or more if [param count] is specified. |
| 23 | </description> |
| 24 | </method> |
| 25 | <method name="try_wait"> |
| 26 | <return type="bool" /> |
| 27 | <description> |
| 28 | Like [method wait], but won't block, so if the value is zero, fails immediately and returns [code]false[/code]. If non-zero, it returns [code]true[/code] to report success. |
| 29 | </description> |
| 30 | </method> |
| 31 | <method name="wait"> |
| 32 | <return type="void" /> |
| 33 | <description> |
| 34 | Waits for the [Semaphore], if its value is zero, blocks until non-zero. |
| 35 | </description> |
| 36 | </method> |
| 37 | </methods> |
| 38 | </class> |