.NET Client Documentation
5.1.1
Search Results for

    Show / Hide Table of Contents

    LockContext Class

    Namespace: Hazelcast.Core
    Assembly: Hazelcast.Net.dll

    Represents a lock context.

    public sealed class LockContext
    Inheritance
    Object
    LockContext
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Remarks

    In .NET, the lock statement is thread-bound i.e. the underlying Monitor is entered by the thread, and can be entered by only one thread at a time, and must be exited by that same thread. However, in an async flow, a Task can be executed by different threads (each time await is used, the Task can resume execution on any available thread). For this reason, the lock statement is not supported in async flows (the compiler raises an error) and explicitly implementing the pattern with an underlying Monitor cannot work, as we cannot guarantee that all code between entering and exiting the monitor executes on the same thread.

    The Hazelcast cluster locks (could be Map locks or FencedLock locks) are owned by a "context" which is represented by a long (64-bits integer) identifier. At codec level, this identifier is passed by the client to the cluster, for all operations that involve locks. In other words, locks in the Hazelcast cluster are context-bound and that context is represented by a long identifier.

    The Java client uses the Java thread unique identifier as the context identifier for the purpose of locks. This has the benefit of being transparent, i.e. all operations naturally "know" the context identifier in which they are operating. The drawback is that, just as with the lock statement, this cannot be supported by .NET async flows.

    The LockContext class provides an explicit representation of such a context, that can be passed to every context-dependent methods (such as locking a fenced lock) to indicate that they operate within that given context. Each instance of the class is assigned a unique long identifier produced by an atomic sequence, which is used as a context (or "thread") identifier at codec and cluster level, for all locking purposes.

    Constructors

    LockContext()

    Initializes a new instance of the LockContext class.

    Properties

    Id

    Gets the unique identifier for of this context.

    In This Article
    Back to top Copyright © 2010-2022 Hazelcast, Inc. All rights reserved.
    Generated by DocFX.