diff options
author | Araq <rumpf_a@web.de> | 2017-02-25 11:18:48 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-02-25 11:18:48 +0100 |
commit | 1961e444c32903d5046f078630e90716c17dff62 (patch) | |
tree | 21334eb10390c005f162c6a821bd03d91f1e8b4b /doc/manual/locking.txt | |
parent | 667acb06a53a47f47dde29c381df0d4bcbf61b94 (diff) | |
parent | 16aafddee598da750dba378cca5bea0126fdf992 (diff) | |
download | Nim-1961e444c32903d5046f078630e90716c17dff62.tar.gz |
Merge branch 'devel' into feature/async-streams
Diffstat (limited to 'doc/manual/locking.txt')
-rw-r--r-- | doc/manual/locking.txt | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/manual/locking.txt b/doc/manual/locking.txt index c00efdd91..c1bd5ca46 100644 --- a/doc/manual/locking.txt +++ b/doc/manual/locking.txt @@ -198,3 +198,22 @@ This is essential so that procs can be called within a ``locks`` section: As usual ``locks`` is an inferred effect and there is a subtype relation: ``proc () {.locks: N.}`` is a subtype of ``proc () {.locks: M.}`` iff (M <= N). + +The ``locks`` pragma can also take the special value ``"unknown"``. This +is useful in the context of dynamic method dispatching. In the following +example, the compiler can infer a lock level of 0 for the ``base`` case. +However, one of the overloaded methods calls a procvar which is +potentially locking. Thus, the lock level of calling ``g.testMethod`` +cannot be inferred statically, leading to compiler warnings. By using +``{.locks: "unknown".}``, the base method can be marked explicitly as +having unknown lock level as well: + +.. code-block:: nim + type SomeBase* = ref object of RootObj + type SomeDerived* = ref object of SomeBase + memberProc*: proc () + + method testMethod(g: SomeBase) {.base, locks: "unknown".} = discard + method testMethod(g: SomeDerived) = + if g.memberProc != nil: + g.memberProc() |