解决读者写者问题
- 实验要求
利用windows的信号量机制编程解决读者写者问题。 - 代码
import threading import time import datetime import numpy as np import hashlib class Job(threading.Thread): def __init__(self, id:str, type:str): super(Job,self).__init__() self.id = id self.type = type def run(self): global read_count if self.type=='read': read_count_lock.acquire() read_count+=1 if read_count==1: write_lock.acquire() print(