-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintinOrder.py
More file actions
33 lines (25 loc) · 956 Bytes
/
printinOrder.py
File metadata and controls
33 lines (25 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Source: https://leetcode.com/problems/print-in-order/
# Author: Miao Zhang
# Date: 2021-04-12
from threading import Lock
class Foo:
def __init__(self):
self.lock1 = Lock()
self.lock2 = Lock()
self.lock1.acquire()
self.lock2.acquire()
def first(self, printFirst: 'Callable[[], None]') -> None:
# printFirst() outputs "first". Do not change or remove this line.
printFirst()
self.lock1.release()
def second(self, printSecond: 'Callable[[], None]') -> None:
# printSecond() outputs "second". Do not change or remove this line.
with self.lock1:
printSecond()
self.lock2.release()
def third(self, printThird: 'Callable[[], None]') -> None:
# printThird() outputs "third". Do not change or remove this line.
with self.lock2:
printThird()