]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gcc/gnu-objective-c-features/synchronization.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gcc / gnu-objective-c-features / synchronization.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. _synchronization:
7
8 Synchronization
9 ***************
10
11 GNU Objective-C provides support for synchronized blocks:
12
13 .. code-block:: objective-c
14
15 @synchronized (ObjCClass *guard) {
16 ...
17 }
18
19 Upon entering the ``@synchronized`` block, a thread of execution
20 shall first check whether a lock has been placed on the corresponding
21 ``guard`` object by another thread. If it has, the current thread
22 shall wait until the other thread relinquishes its lock. Once
23 ``guard`` becomes available, the current thread will place its own
24 lock on it, execute the code contained in the ``@synchronized``
25 block, and finally relinquish the lock (thereby making ``guard``
26 available to other threads).
27
28 Unlike Java, Objective-C does not allow for entire methods to be
29 marked ``@synchronized``. Note that throwing exceptions out of
30 ``@synchronized`` blocks is allowed, and will cause the guarding
31 object to be unlocked properly.
32
33 Because of the interactions between synchronization and exception
34 handling, you can only use ``@synchronized`` when compiling with
35 exceptions enabled, that is with the command line option
36 :option:`-fobjc-exceptions`.