Skip to content

Commit d771dd0

Browse files
committed
add wait tiem refresh to the thread
1 parent d41785f commit d771dd0

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/Apache.IoTDB/ConcurrentClientQueue.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Return(Client client)
2424
{
2525
Monitor.Enter(ClientQueue);
2626
ClientQueue.Enqueue(client);
27-
Monitor.Pulse(ClientQueue);
27+
Monitor.PulseAll(ClientQueue); // wake up all threads waiting on the queue, refresh the waiting time
2828
Monitor.Exit(ClientQueue);
2929
Thread.Sleep(0);
3030
}
@@ -52,15 +52,17 @@ public Client Take()
5252
{
5353
Client client = null;
5454
Monitor.Enter(ClientQueue);
55-
if (ClientQueue.IsEmpty)
56-
{
57-
Monitor.Wait(ClientQueue, TimeSpan.FromSeconds(Timeout));
58-
}
59-
if (!ClientQueue.TryDequeue(out client))
60-
{
61-
}
62-
else
63-
{
55+
while(true){
56+
bool timeout = false;
57+
if (ClientQueue.IsEmpty)
58+
{
59+
timeout = !Monitor.Wait(ClientQueue, TimeSpan.FromSeconds(Timeout));
60+
}
61+
ClientQueue.TryDequeue(out client);
62+
63+
if(client != null || timeout){
64+
break;
65+
}
6466
}
6567
Monitor.Exit(ClientQueue);
6668
if (client == null)

0 commit comments

Comments
 (0)