New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the reason to deprecate Lock
in swoole 4.4 ?
#2601
Comments
Bad Case:<?php
$lock = new Swoole\Lock();
$c = 2;
while ($c--) {
go(function () use ($lock) {
$lock->lock();
Co::sleep(1);
$lock->unlock();
});
} |
This will cause a deadlock |
Thanks. I try to elaborate. Please tell me if I am wrong. I think the problem is because of after reading static void sleep_timeout(swTimer *timer, swTimer_node *tnode)
{
((Coroutine *) tnode->data)->resume();
}
int System::sleep(double sec)
{
Coroutine* co = Coroutine::get_current_safe();
if (swTimer_add(&SwooleG.timer, (long) (sec * 1000), 0, co, sleep_timeout) == NULL)
{
return -1;
}
co->yield();
return 0;
} the yield may not be resumed after the next coroutine comes in. |
@abbychau 死锁的原因是Swoole的协程是在同一个线程里面跑,也就是说,这个线程把自己给锁住了。如果未来Swoole的协程可以在不同的线程里面跑,应该是不会死锁的。 |
@abbychau Swoole以后应该是会提供协程锁 |
I think so too. |
This will be very cool. 😎 kotlinx implemented it. |
I found 废弃Lock模块,废弃原因:在协程模式下加锁可能存在问题,可使用chan实现协程版本的锁.
What is the concrete reason? or what are the error instances?
The text was updated successfully, but these errors were encountered: