我正在尝试在 2 个 Lua 通道之间使用锁,但观察到两个通道同时进入 lock_func ..下面是片段
Code Snippet
==================
require"lanes"
local linda = lanes.linda()
lock_func = lanes.genlock(linda,"M",1)
local function lock_func()
print("Lock Acquired")
while(true) do
end
end
local function readerThread()
print("readerThread acquiring lock")
lock_func()
end
local function writerThread()
print("writerThread acquiring lock")
lock_func()
end
Thread1= lanes.gen("*",{globals = _G},writerThread)
Thread2= lanes.gen("*",{globals = _G},readerThread)
T1 = Thread1()
T2 = Thread2()
T1:join()
T2:join()
从下面的输出我们可以看到两条通道同时进入了 lock_func 函数
output
==================
writerThread acquiring lock
Lock Acquired
readerThread acquiring lock
Lock Acquired
从上面的代码实现锁有什么问题吗?