ikvm_manager.cpp: fix a deadlock issue
There is a deadlock in the case that the screen resolution is altered.
The probability of deadlock will increase as the frame rate increases.
The deadlock is likely to be reproduced when the frame rate is set to
above 30fps. The scenario of deadlock is described as below.
mainThread serverThread
|
setServerDone
|
setVideoDone <----------switch to mainThread <----set serverDone to true
|
waitServer
|
serverDone is set to FALSE
|
screen resolution has been changed
|
videoDone is set to FALSE
|
waitServer(A, wait serverThread to set serverDone to TRUE, \
| block mainthread)
|
----------switch to serverThread-------------------> waitVideo
|
|
(B, wait mainthread to set videoDone to TRUE, block serverThread)
A)The main thread is blocked for waiting serverThread to set serverDone,
at the meantime, B)The serverThread is blocked for waiting main thread
to set videoDone. So a deadlock is generated.
The patch delays to set videoDone to false after the mainThread is
blocked for waiting serverDone, then the value of the videoDone
maintains true. So the serverThread is unblocked as the videoDone is
true. After serverThread finishes executing setServerDone, mainThread
is unblocked and continues executing.
Change-Id: If30d2cd5c493a909397fde43d1cf538cc28f3df2
Signed-off-by: Min Wang <wangmin@phytium.com.cn>
diff --git a/ikvm_manager.cpp b/ikvm_manager.cpp
index 2f66fd5..b283b87 100644
--- a/ikvm_manager.cpp
+++ b/ikvm_manager.cpp
@@ -31,8 +31,8 @@
if (video.needsResize())
{
- videoDone = false;
waitServer();
+ videoDone = false;
video.resize();
server.resize();
setVideoDone();