From 94f1c67ab32637071db859f225e08d8333a6c6f9 Mon Sep 17 00:00:00 2001 From: corwinn Date: Tue, 21 Mar 2023 23:43:43 +0200 Subject: [PATCH] os: windows: eliminate a deadlock --- async/h3r_taskthread.h | 28 +++++++++++++++++++++------- diagrams/async_whiteboard.dia | Bin 0 -> 7358 bytes h3r_game.cpp | 4 ++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 diagrams/async_whiteboard.dia diff --git a/async/h3r_taskthread.h b/async/h3r_taskthread.h index 571c198..95a41d1 100644 --- a/async/h3r_taskthread.h +++ b/async/h3r_taskthread.h @@ -63,11 +63,11 @@ class TaskThread final public TaskThread() : _tproc {*this}, _thr {_tproc}, Task {*this} {} public ~TaskThread() { - while (! _running) + while (! _running) //DL_HUNTER printf ("<%p> ~ waiting\n", this); ; _tproc.stop = true; _nothing_to_do.GoGoGo (); - // printf ("<%p> GoGoGo\n", this); + //DL_HUNTER printf ("<%p> ~ GoGoGo\n", this); _thr.Stop (); } @@ -92,8 +92,18 @@ class TaskThread final ____ {_p._d_lock}; return _v = v; } - public operator bool() const { return _v; } - public bool operator !() const { return !_v; } + public operator bool() const + { + __pointless_verbosity::CriticalSection_Acquire_finally_release + ____ {_p._d_lock}; + return _v; + } + public bool operator !() const + { + __pointless_verbosity::CriticalSection_Acquire_finally_release + ____ {_p._d_lock}; + return !_v; + } } _dirty; // setup part inline IAsyncTask & Do(IAsyncTask * p) @@ -144,10 +154,14 @@ class TaskThread final _running = true; while (! _tproc.stop) { // _nothing_to_do.Lock () is unlocked while the thread waits, only + //DL_HUNTER printf ("<%p> wait\n", this); _nothing_to_do.Wait (); + //DL_HUNTER printf ("<%p> work\n", this); // OS::Log_stdout ("p:%p, _tproc.dirty:%d" EOL, // &_tproc, (_tproc._dirty ? 1 : 0)); if (_tproc._dirty) Do (); // laundry + //DL_HUNTER printf ("<%p> work done: dirty: %d\n", this, + // (bool)_tproc._dirty); // This can't continue - I'll have to change the CC. Because when // a rendering requests 60 distinct resources, this here introduces // significant delay - render-wise. If I lower the poll interval it @@ -165,14 +179,14 @@ class TaskThread final private inline IAsyncTask & Do(IAsyncTask * it) { - // printf ("<%p> Do(it)\n", this); + //DL_HUNTER printf ("<%p> Do(it)\n", this); auto & result = _tproc.Do (it); // Because the task thread might fail to actually reach the line where // this state is set, prior the task issuer steps in here. - while (! _running) + while (! _running) //DL_HUNTER printf ("<%p> Set waiting\n", this); ; _nothing_to_do.GoGoGo (); - // printf ("<%p> GoGoGo\n", this); + //DL_HUNTER printf ("<%p> Set GoGoGo\n", this); return result; } diff --git a/diagrams/async_whiteboard.dia b/diagrams/async_whiteboard.dia new file mode 100644 index 0000000000000000000000000000000000000000..2a4521371145f1a1cb218c40d84c5c22fc9b6bc4 GIT binary patch literal 7358 zcmV;v96{qBiwFP!000021MOW~bK}Obe)q3XZC-M!XzbiCtE^LYoQtdCIOS|Ak1R;U zN;sxShNN~aKb+rwW`?B13qXPx^oZoPs&;kZ5Q71yr~B*6*MIoquMfkkPsMarjz{m` z(2TsfDn_^CK{>j6|K{Hx{_?eX^T%(#`oo~i-?@Kx)BNGey<;@|MKB5f9nRlee=y%S6Ay7807QZ|84o#d_JF+H;?n;YLq_| z@88_yx4+y?$B(1Io5iT*xZCk?JiYpq58uD}-N*3t=I!z_Z#S;9=h~C}uDF>N`7iaC zChp7HHkY0h)9uSXOvba)4Vgbpc81hk$N#@JW;tr+2955%`Q5kTcZ*wE{^8|XRX18Y z$^0Ro-j$=>dEB!ZE*=ES3}eha3~7xeT4=g@CdW^AlXkjc+Ucfgrz>au$#^=S=H+~M z%A4_cSmdL{tn=w((SDxUZ9a5cY~QjXR`Ic%&&LPu|6@L!HCe#o&(G3!tmNKJ%fWuZ z-561GmCxm1e&7EU=y5Hs{seUOPvxw<85UJ{UykOTUH++?%Wr==;q-oad*p6dT&-3; z3``*ldAxeKdn^aV?7%kL98+_p`{l5=ho1WOxTX(g@uw|i9i|xOPsMb3`R`uT^wshM zUYZ1(2G0CDC=Ie7o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e)PY;?=$&A)o2&yIL%zzu0n;Y>G z&JB{T#P?IUrTSK~&VItf*^`qUib* zqhOCBfBofAWE37ncoZGpgLo93+);Gc#Z5_kIgRKsP$nH7x(qFtbV6%&2F|3@eo2@x z^QGrhW*?AGCrMRJ7ES_mc&7`9Qo_5?77AWl$Te-D6KD&C+5)u&YKs%s78;rhu0RIp|(J6f!gB4 zwFUORPOB|c7urI?YYVZaEmQ(+AyHePwm@xh;@ScU!P06A-G#O=@Y+JJX$zY`TNu<9 zs4Y-ioVd2Is4XDMy1pxZD~oAOH3cQn)m_rY1fLtJ4QVqajP?D?38yA-NE$;!sEd)7 zr~6IuTmN7^#qQ#&V;%GWz2u<*K5p0E%eGL0egDzVj_J5r`5IPlB<85pt=bRp<-2`u kV=PJK;`d?xR7}75YVnKvcQ?%+zWM6^0e+#N)Rct+05;uY1ONa4 literal 0 HcmV?d00001 diff --git a/h3r_game.cpp b/h3r_game.cpp index 8b402c2..ca6c85f 100644 --- a/h3r_game.cpp +++ b/h3r_game.cpp @@ -106,6 +106,10 @@ void Game::SilentLog(bool v) /*static*/ void Game::ProcessThings() { if (Game::MainWindow) Game::MainWindow->ProcessMessages (); + // A tight loop makes ResManagerInit above infinite ?! + // The pointless sync at the BoolProperty at the TaskThread resolves it, + // but I'm adding this here just in case, until I understand whats going on. + else OS::Thread::Sleep (1);//TODO understand the odd deadlock } /*static*/ Stream * Game::GetResource(const String & name)