mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
@@ -59,6 +59,7 @@ proc signal*(cond: var Cond) {.inline.} =
|
||||
template withLock*(a: Lock, body: untyped) =
|
||||
## Acquires the given lock, executes the statements in body and
|
||||
## releases the lock after the statements finish executing.
|
||||
mixin acquire, release
|
||||
a.acquire()
|
||||
{.locks: [a].}:
|
||||
try:
|
||||
|
||||
10
tests/stdlib/tlocks.nim
Normal file
10
tests/stdlib/tlocks.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
discard """
|
||||
output: '''3'''
|
||||
cmd: "nim $target --threads:on $options $file"
|
||||
"""
|
||||
|
||||
#bug #6049
|
||||
import uselocks
|
||||
|
||||
var m = createMyType[int]()
|
||||
echo $m.use()
|
||||
11
tests/stdlib/uselocks.nim
Normal file
11
tests/stdlib/uselocks.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
import locks
|
||||
|
||||
type MyType* [T] = object
|
||||
lock: Lock
|
||||
|
||||
proc createMyType*[T]: MyType[T] =
|
||||
initLock(result.lock)
|
||||
|
||||
proc use* (m: var MyType): int =
|
||||
withLock m.lock:
|
||||
result = 3
|
||||
Reference in New Issue
Block a user