summary refs log tree commit diff stats
path: root/tests/parallel/tguard2.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parallel/tguard2.nim')
-rw-r--r--tests/parallel/tguard2.nim27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/parallel/tguard2.nim b/tests/parallel/tguard2.nim
new file mode 100644
index 000000000..661893bb5
--- /dev/null
+++ b/tests/parallel/tguard2.nim
@@ -0,0 +1,27 @@
+discard """
+  errormsg: "unguarded access: c.i"
+  line: 25
+"""
+
+type
+  ProtectedCounter[T] = object
+    i {.guard: L.}: T
+    L: int
+
+var
+  c: ProtectedCounter[int]
+
+c.i = 89
+
+template atomicRead(L, x): untyped =
+  {.locks: [L].}:
+    x
+
+proc main =
+  {.locks: [c.L].}:
+    inc c.i
+    discard
+  echo(atomicRead(c.L, c.i))
+  echo c.i
+
+main()