summaryrefslogtreecommitdiffstats
path: root/doc/classes
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-05-15 13:42:52 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-05-15 13:42:52 +0200
commit1d83a4c5a588ae839983ed9a7227c7d2911a856c (patch)
tree3d1cd0ffbd5186a38da183abbd433696a8bec7b8 /doc/classes
parent78f9da7a9fac3cf4388639f34f1671e6d7e87533 (diff)
parent6189ab5291e54dfe090a081cf292e3d6f9c6b8b1 (diff)
downloadredot-engine-1d83a4c5a588ae839983ed9a7227c7d2911a856c.tar.gz
Merge pull request #72249 from RandomShaper/robust_sync
Robustify multi-threading primitives
Diffstat (limited to 'doc/classes')
-rw-r--r--doc/classes/Mutex.xml6
-rw-r--r--doc/classes/Semaphore.xml4
-rw-r--r--doc/classes/Thread.xml5
3 files changed, 15 insertions, 0 deletions
diff --git a/doc/classes/Mutex.xml b/doc/classes/Mutex.xml
index 78202229ed..ab1fad9624 100644
--- a/doc/classes/Mutex.xml
+++ b/doc/classes/Mutex.xml
@@ -5,6 +5,11 @@
</brief_description>
<description>
A synchronization mutex (mutual exclusion). This is used to synchronize multiple [Thread]s, and is equivalent to a binary [Semaphore]. It guarantees that only one thread can ever acquire the lock at a time. A mutex can be used to protect a critical section; however, be careful to avoid deadlocks.
+ It's of the recursive kind, so it can be locked multiple times by one thread, provided it also unlocks it as many times.
+ [b]Warning:[/b]
+ To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met:
+ - By the time a [Mutex]'s reference count reaches zero and therefore it is destroyed, no threads (including the one on which the destruction will happen) must have it locked.
+ - By the time a [Thread]'s reference count reaches zero and therefore it is destroyed, it must not have any mutex locked.
</description>
<tutorials>
<link title="Using multiple threads">$DOCS_URL/tutorials/performance/using_multiple_threads.html</link>
@@ -29,6 +34,7 @@
<description>
Unlocks this [Mutex], leaving it to other threads.
[b]Note:[/b] If a thread called [method lock] or [method try_lock] multiple times while already having ownership of the mutex, it must also call [method unlock] the same number of times in order to unlock it correctly.
+ [b]Warning:[/b] Calling [method unlock] more times that [method lock] on a given thread, thus ending up trying to unlock a non-locked mutex, is wrong and may causes crashes or deadlocks.
</description>
</method>
</methods>
diff --git a/doc/classes/Semaphore.xml b/doc/classes/Semaphore.xml
index c95917b7bb..32eb69fe8c 100644
--- a/doc/classes/Semaphore.xml
+++ b/doc/classes/Semaphore.xml
@@ -5,6 +5,10 @@
</brief_description>
<description>
A synchronization semaphore which can be used to synchronize multiple [Thread]s. Initialized to zero on creation. Be careful to avoid deadlocks. For a binary version, see [Mutex].
+ [b]Warning:[/b]
+ To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met:
+ - By the time a [Semaphore]'s reference count reaches zero and therefore it is destroyed, no threads must be waiting on it.
+ - By the time a [Thread]'s reference count reaches zero and therefore it is destroyed, it must not be waiting on any semaphore.
</description>
<tutorials>
<link title="Using multiple threads">$DOCS_URL/tutorials/performance/using_multiple_threads.html</link>
diff --git a/doc/classes/Thread.xml b/doc/classes/Thread.xml
index 2b4ef65f0c..fcb803b15a 100644
--- a/doc/classes/Thread.xml
+++ b/doc/classes/Thread.xml
@@ -6,6 +6,11 @@
<description>
A unit of execution in a process. Can run methods on [Object]s simultaneously. The use of synchronization via [Mutex] or [Semaphore] is advised if working with shared objects.
[b]Note:[/b] Breakpoints won't break on code if it's running in a thread. This is a current limitation of the GDScript debugger.
+ [b]Warning:[/b]
+ To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met by the time a [Thread]'s reference count reaches zero and therefore it is destroyed:
+ - It must not have any [Mutex] objects locked.
+ - It must not be waiting on any [Semaphore] objects.
+ - [method wait_to_finish] should have been called on it.
</description>
<tutorials>
<link title="Using multiple threads">$DOCS_URL/tutorials/performance/using_multiple_threads.html</link>