< Summary

Information
Class: LeetCode.Concurrency.PrintInOrder.PrintInOrderMonitor
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Concurrency\PrintInOrder\PrintInOrderMonitor.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 61
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
First(...)100%11100%
Second(...)100%22100%
Third(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Concurrency\PrintInOrder\PrintInOrderMonitor.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Concurrency.PrintInOrder;
 13
 14/// <inheritdoc />
 15public class PrintInOrderMonitor : IPrintInOrder
 16{
 317    private readonly object _lock = new();
 318    private int _step = 1;
 19
 20    public void First(Action printFirst)
 321    {
 322        lock (_lock)
 323        {
 324            printFirst.Invoke();
 25
 326            _step = 2;
 27
 328            Monitor.PulseAll(_lock);
 329        }
 330    }
 31
 32    public void Second(Action printSecond)
 333    {
 334        lock (_lock)
 335        {
 436            while (_step != 2)
 137            {
 138                Monitor.Wait(_lock);
 139            }
 40
 341            printSecond.Invoke();
 42
 343            _step = 3;
 44
 345            Monitor.PulseAll(_lock);
 346        }
 347    }
 48
 49    public void Third(Action printThird)
 350    {
 351        lock (_lock)
 352        {
 653            while (_step != 3)
 354            {
 355                Monitor.Wait(_lock);
 356            }
 57
 358            printThird.Invoke();
 359        }
 360    }
 61}