Utilities: BlockingQueue: Bugfix: TryDequeue would block infinitely if called after Stop was invoked

This commit is contained in:
Tal Aloni 2025-05-01 17:40:15 +03:00
parent 351f23ead9
commit 21313ac030

View file

@ -1,13 +1,11 @@
/* Copyright (C) 2016-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2016-2025 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version. * either version 3 of the License, or (at your option) any later version.
*/ */
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Text;
namespace Utilities namespace Utilities
{ {
@ -56,8 +54,12 @@ namespace Utilities
lock (m_queue) lock (m_queue)
{ {
while (m_queue.Count == 0) while (m_queue.Count == 0)
{
if (!m_stopping)
{ {
Monitor.Wait(m_queue); Monitor.Wait(m_queue);
}
if (m_stopping) if (m_stopping)
{ {
item = default(T); item = default(T);