Exemple #1
0
        Acquire()
        {
            if (Unmanaged.WaitForSingleObject(this.hMutex, INFINITE) == ABANDONED)
            {
                Console.WriteLine("warning: mutex abandoned\n{0}", System.Environment.StackTrace);
            }

            this.owner  = Thread.CurrentThread.ManagedThreadId;
            this.count += 1;
            return(this.count);
        }
Exemple #2
0
        TryAcquire()
        {
            int result = Unmanaged.WaitForSingleObject(this.hMutex, 0);

            if (result == TIMEOUT)
            {
                return(false);
            }
            if (result == ABANDONED)
            {
                Console.WriteLine("warning: mutex abandoned\n{0}", System.Environment.StackTrace);
            }

            this.owner  = Thread.CurrentThread.ManagedThreadId;
            this.count += 1;
            return(true);
        }