public CriticalRegion startCriticalRegion(String regionDescription) {
        List<String> regionDescriptions = threadLocalDescriptions.get();
        regionDescriptions.add(regionDescription);
        Thread threadAtStart = Thread.currentThread();

        return () -> {
            regionDescriptions.remove(regionDescription);

            Thread treadAtClose = Thread.currentThread();
            if (threadAtStart != treadAtClose) {
                throw new IllegalStateException(name + ": A critical region cannot cross threads: " +
                        regionDescription);
            }
        };
    }
Start of the critical region, within which {@link #assertOutsideCriticalRegions(String)} will throw.
service-monitor/src/main/java/com/yahoo/vespa/service/duper/CriticalRegionChecker.java