-6
燈光開關信號的正確替代形式應該如何在非面向對象的C語言中看起來像? lightswitch信號燈的Python參考文件寫在這份文件Little Book Of Semaphores中。C中的燈光開關信號的正確形式
的LightSwitch代碼:
class Lightswitch :
def __init__(self):
self.counter = 0
self.mutex = Semaphore(1)
def lock(self, semaphore):
self.mutex.wait()
self.counter += 1
if self.counter == 1:
semaphore.wait()
self.mutex.signal()
def unlock(self, semaphore):
self.mutex.wait()
self.counter -= 1
if self.counter == 0:
semaphore.signal()
self.mutex.signal()
「_How應的LightSwitch的正確的替代形式旗語看起來像面向C語言的非對象_ 「只是說」爲我編寫代碼「的奇特方式,這不是本網站的目的。 – csmckelvey
@csm_dev沒有必要「爲我寫代碼」。你可以指出一些想法,我應該怎麼做。沒關係,我反正做了。祝你今天愉快 :) – Amphoru