|
14 | 14 | * cause memory leaks since memory usage could keep increasing as new requests keep coming in. In general, it's not |
15 | 15 | * recommended to keep creating/destroying locks since this could cause memory leaks. |
16 | 16 | * |
17 | | - * Locks should not be used in coroutines, especially when there are coroutine switching between method calls to |
18 | | - * \Swoole\Lock::lock() and \Swoole\Lock::unlock(). For example, the following example will cause deadlock: |
| 17 | + * This Lock class is not coroutine-friendly. It should not be used across different coroutines, especially when there |
| 18 | + * are coroutine switching between method calls to \Swoole\Lock::lock() and \Swoole\Lock::unlock(). For example, the |
| 19 | + * following example will cause deadlock: |
19 | 20 | * |
20 | 21 | * Swoole\Coroutine\run(function () { |
21 | 22 | * $lock = new Swoole\Lock(); |
|
28 | 29 | * } |
29 | 30 | * }); |
30 | 31 | * |
31 | | - * If you think you need to use locks with coroutines, you can probably use channels instead. |
| 32 | + * If you think you need to use locks with coroutines, there are two options: |
| 33 | + * 1. use channels (before Swoole 6.0.1). |
| 34 | + * 2. use class \Swoole\Coroutine\Lock (since Swoole 6.0.1). |
32 | 35 | * |
33 | 36 | * @see \Swoole\Thread\Lock Use this instead when PHP is compiled with Zend Thread Safety (ZTS) enabled. |
| 37 | + * @see \Swoole\Coroutine\Lock Use this instead when using locks accross coroutines. |
34 | 38 | * @see https://github.com/deminy/swoole-by-examples/blob/master/examples/csp/deadlocks/swoole-lock.php |
35 | 39 | * @not-serializable Objects of this class cannot be serialized. |
36 | 40 | */ |
@@ -159,13 +163,4 @@ public function trylock_read(): bool |
159 | 163 | public function unlock(): bool |
160 | 164 | { |
161 | 165 | } |
162 | | - |
163 | | - /** |
164 | | - * Destroy the lock and release any resources used by the lock. |
165 | | - * |
166 | | - * After calling this method, the lock object should not be used anymore. |
167 | | - */ |
168 | | - public function destroy(): void |
169 | | - { |
170 | | - } |
171 | 166 | } |
0 commit comments