<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Lock innerhalb von mutex::unlock() ?]]></title><description><![CDATA[<p>Ich habe hier ein Problem mit einem Thread, der nicht zum Ende kommt.<br />
gdb sagt mir, der Thread hängt in:</p>
<blockquote>
<p>#0 __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135<br />
#1 0x00007ffff6d495b0 in pthread_cond_broadcast@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S:136<br />
#2 0x00007ffff752ed59 in std::condition_variable::notify_all() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br />
#3 0x0000000000410014 in std::shared_timed_mutex::unlock (this=0x7fffffffd608) at /usr/include/c++/4.9/shared_mutex:159<br />
#4 0x00000000004109c6 in std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a>::unlock (this=0x7fffeb5fdde0) at /usr/include/c++/4.9/mutex:530<br />
#5 0x000000000040f2ed in MyClass::tick (this=0x7fffffffd5f0, timedelta=0,050000000000000003) at MyClass.cpp:48</p>
</blockquote>
<p>wobei die Zeilen 47/48 in MyClass.cpp lauten:</p>
<pre><code>assert(excllock.owns_lock());
excllock.unlock();
</code></pre>
<p>und <em>excllock</em> ist vom Typ <em>std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a></em>.</p>
<p>Wie kann das überhaupt sein, dass der Thread innerhalb eines Aufrufs von <strong>un</strong>lock hängen bleibt? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/333552/lock-innerhalb-von-mutex-unlock</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 23:51:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/333552.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Jul 2015 01:55:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Wed, 15 Jul 2015 01:55:56 GMT]]></title><description><![CDATA[<p>Ich habe hier ein Problem mit einem Thread, der nicht zum Ende kommt.<br />
gdb sagt mir, der Thread hängt in:</p>
<blockquote>
<p>#0 __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135<br />
#1 0x00007ffff6d495b0 in pthread_cond_broadcast@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S:136<br />
#2 0x00007ffff752ed59 in std::condition_variable::notify_all() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br />
#3 0x0000000000410014 in std::shared_timed_mutex::unlock (this=0x7fffffffd608) at /usr/include/c++/4.9/shared_mutex:159<br />
#4 0x00000000004109c6 in std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a>::unlock (this=0x7fffeb5fdde0) at /usr/include/c++/4.9/mutex:530<br />
#5 0x000000000040f2ed in MyClass::tick (this=0x7fffffffd5f0, timedelta=0,050000000000000003) at MyClass.cpp:48</p>
</blockquote>
<p>wobei die Zeilen 47/48 in MyClass.cpp lauten:</p>
<pre><code>assert(excllock.owns_lock());
excllock.unlock();
</code></pre>
<p>und <em>excllock</em> ist vom Typ <em>std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a></em>.</p>
<p>Wie kann das überhaupt sein, dass der Thread innerhalb eines Aufrufs von <strong>un</strong>lock hängen bleibt? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459825</guid><dc:creator><![CDATA[wx++]]></dc:creator><pubDate>Wed, 15 Jul 2015 01:55:56 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Wed, 15 Jul 2015 18:51:05 GMT]]></title><description><![CDATA[<p>Wie du siehst, gibt es keine Antworten auf deinen Beitrag. Das ist kein Zufall, sondern liegt an deinem Beitrag.<br />
<a href="https://www.c-plusplus.net/forum/304133">Wie man Probleme nachstellbar und nachvollziehbar macht</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459933</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459933</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 15 Jul 2015 18:51:05 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Wed, 15 Jul 2015 19:14:45 GMT]]></title><description><![CDATA[<p>OK, dann so:<br />
Gibt es irgendwelche denkbaren Umstände, unter denen ein Aufruf von std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a>::unlock() blockieren könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459937</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459937</guid><dc:creator><![CDATA[wx++]]></dc:creator><pubDate>Wed, 15 Jul 2015 19:14:45 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Wed, 15 Jul 2015 19:18:23 GMT]]></title><description><![CDATA[<p>wx++ schrieb:</p>
<blockquote>
<p>Gibt es irgendwelche denkbaren Umstände, unter denen ein Aufruf von std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a>::unlock() blockieren könnte?</p>
</blockquote>
<p>Offensichtlicherweise das Szenario in deinem Code. Wieso also uns raten lassen, wenn deine Frage doch eigentlich ist, was an deinem Code falsch <em>ist</em>, nicht was was falsch sein <em>könnte</em>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459938</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 15 Jul 2015 19:18:23 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 01:11:15 GMT]]></title><description><![CDATA[<p>wx++ schrieb:</p>
<blockquote>
<p>OK, dann so:<br />
Gibt es irgendwelche denkbaren Umstände, unter denen ein Aufruf von std::unique_lock<a href="std::shared%5C_timed_mutex" rel="nofollow">std::shared\_timed_mutex</a>::unlock() blockieren könnte?</p>
</blockquote>
<p>Ein denkbarer Umstand wäre, dass der aktuelle Thread nicht das Lock auf den Mutex hält, dann wäre das <code>unlock()</code> meines Wissens undefined behavior. Das solltest du aber eigentlich durch deine Assertion ausgeschlossen haben. Ist es vielleicht möglich, dass du nur ein Shared-Lock auf den Mutex hältst? <code>unlock()</code> ist soweit ich weiss nur für exklusive Locks (bin mir nicht sicher, aber ich denke auch dann hätte die Assertion fehlschlagen müssen).</p>
<p>Generell hat SeppJ recht. Mehr kann man nur mit mehr Kontext sagen. Allerdings muss ich zugeben, dass ich das auch etwas seltsam finde, dass ausgerechnet das <code>unlock()</code> blockiert. Der Callstack legt ausserdem nahe, dass er blockiert, während er versucht eine interne Condition Variable zu benachrichtigen. Auch wenn man wegen der wenigen Infos nicht viel sagen kann, sagt mir mein Bauchgefühl, dass du eventuell auf einen libstdc++-Bug gestossen sein könntest. Immerhin ist der <code>shared_timed_mutex</code> soweit ich weiss noch ein relativ neues Feature.</p>
<p>Lässt sich der Deadlock eigentlich zuverlässig reproduzieren? Optimal wäre natürlich ein möglichst kurzes Testprogramm bei dem dieser Fehler auftritt. Dann lässt sich leichter sagen, ob es ein Standardbibliothek-Bug ist, oder ob du selbst etwas komisches machst. Eine weitere Möglichkeit wäre auch, den Mutex durch eine andere Implementierung zu ersetzen. Soweit ich weiss, unterstützt der z.b. der <code>boost::shared_mutex</code> die selbe Funktionalität.</p>
<p>Finnegan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459949</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459949</guid><dc:creator><![CDATA[Finnegan]]></dc:creator><pubDate>Thu, 16 Jul 2015 01:11:15 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 04:30:26 GMT]]></title><description><![CDATA[<p>Vermutlich hast du die <code>shared_timed_mutex</code> schon zerstört bevor du versuchst sie zu unlocken.<br />
(Oder die Implementierung der <code>shared_timed_mutex</code> ist wirklich fehlerhaft - aber ich gehe erstmal immer von nem eigenen Fehler aus, also auch wenn ich meine eigenen Programme debugge.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459957</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 16 Jul 2015 04:30:26 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 06:23:40 GMT]]></title><description><![CDATA[<blockquote>
<p>Vermutlich hast du die shared_timed_mutex schon zerstört bevor du versuchst sie zu unlocken.</p>
</blockquote>
<p>Das ist eine gute Idee, der ich nachgehen werde.</p>
<p>Ansonsten habe ich noch diese Antwort gefunden, signal handlers sind in meinem Fall aber nicht involviert: <a href="http://stackoverflow.com/questions/4345315/pthread-cond-signal-deadlocks" rel="nofollow">http://stackoverflow.com/questions/4345315/pthread-cond-signal-deadlocks</a> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459966</guid><dc:creator><![CDATA[wx++]]></dc:creator><pubDate>Thu, 16 Jul 2015 06:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 08:07:49 GMT]]></title><description><![CDATA[<p>BTW: Wenn der Verdacht zutrifft, dann sollte man vermutlich dem Library-Dev-Team den Vorschlag schicken ein <code>assert(!locked())</code> in den dtor einzubauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459973</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 16 Jul 2015 08:07:49 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 10:37:25 GMT]]></title><description><![CDATA[<p>Anscheinend hatte hustbaer den richtigen Riecher. Ein anderer Thread hat die Struktur zu der der mutex gehört u.U. schon dealloziert während der &quot;fehlerhafte&quot; Thread noch lief.</p>
<p>Das Problem ist nur sporadisch aufgetreten, aber ich konnte es jetzt auch in einer größeren Anzahl Tests nicht mehr reproduzieren und nehme daher an, dass damit die Ursache gefunden ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2459991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2459991</guid><dc:creator><![CDATA[wx++]]></dc:creator><pubDate>Thu, 16 Jul 2015 10:37:25 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 11:53:39 GMT]]></title><description><![CDATA[<p>wx++ schrieb:</p>
<blockquote>
<p>Anscheinend hatte hustbaer den richtigen Riecher. Ein anderer Thread hat die Struktur zu der der mutex gehört u.U. schon dealloziert während der &quot;fehlerhafte&quot; Thread noch lief.</p>
</blockquote>
<p>Jo, das klingt nach einem äußerst &quot;denkbaren Umstand&quot; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
BTW... falls du sowas ähnliches nicht eh schon machst, ich habe speziell bei solchen Sachen wie mit deiner Struktur immer <code>std::shared_ptr</code> als sehr nützlich empfunden.</p>
<p>Finnegan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2460000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2460000</guid><dc:creator><![CDATA[Finnegan]]></dc:creator><pubDate>Thu, 16 Jul 2015 11:53:39 GMT</pubDate></item><item><title><![CDATA[Reply to Lock innerhalb von mutex::unlock() ? on Thu, 16 Jul 2015 15:07:18 GMT]]></title><description><![CDATA[<p>Gar kein Riecher.<br />
Ich hab' einfach nur <code>__lll_lock_wait</code> gegoogelt und dann diesen Fred hier gefunden (3. Treffer mit Google!):</p>
<p><a href="http://stackoverflow.com/questions/8248458/pthread-cond-signal-causing-deadlock" rel="nofollow">http://stackoverflow.com/questions/8248458/pthread-cond-signal-causing-deadlock</a></p>
<p>Nachdem das exakt das selbe Problem ist wie du in deinem Callstack hast ( <code>pthread_cond_broadcast</code> hängt obwohl es niemals hängen dürfte)...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2460018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2460018</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 16 Jul 2015 15:07:18 GMT</pubDate></item></channel></rss>