Skip to content

Commit d325338

Browse files
authored
Merge pull request #95 from eedalong/fix/concurrency
Modify the issue of premature thread exit caused by Monitor.Wait().
2 parents dea6aff + 828bf7e commit d325338

File tree

6 files changed

+32
-44
lines changed

6 files changed

+32
-44
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.user
55
*.userosscache
66
*.sln.docstates
7+
**/tmp
78

89
# Build results
910
[Dd]ebug/
@@ -65,7 +66,7 @@ publish/
6566

6667

6768
### Rider ###
68-
.idea
69-
/.vs/Apache.IoTDB/FileContentIndex
70-
/.vs/ProjectEvaluation
71-
/.vs/Apache.IoTDB
69+
.idea
70+
/.vs/Apache.IoTDB/FileContentIndex
71+
/.vs/ProjectEvaluation
72+
/.vs/Apache.IoTDB

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ We have prepared Nuget Package for C# users. Users can directly install the clie
4141
dotnet add package Apache.IoTDB
4242
```
4343

44-
Note that the `Apache.IoTDB` package only supports `.net 5.0`. If you are using `.net framework 4.x`, please refer to the section [starting from .net framework 4.x](#starting-from-net-framework-4x).
44+
Note that the `Apache.IoTDB` package only supports versions greater than `.net framework 4.6.1`.(#starting-from-net-framework-4x).
4545

4646
## Prerequisites
4747

48-
.NET SDK Version == 5.0
48+
.NET SDK Version >= 5.0
49+
.NET Framework >= 4.6.1
4950

5051
## How to Use the Client (Quick Start)
5152

@@ -54,7 +55,8 @@ Users can refer to the test code in [tests](https://github.com/eedalong/Apache-I
5455
## Developer environment requirements for iotdb-client-csharp
5556

5657
```
57-
.NET SDK Version == 5.0
58+
.NET SDK Version >= 5.0
59+
.NET Framework >= 4.6.1
5860
ApacheThrift >= 0.14.1
5961
NLog >= 4.7.9
6062
```
@@ -67,13 +69,4 @@ NLog >= 4.7.9
6769
### Command Line Tools
6870

6971
## Publish your own client on nuget.org
70-
You can find out how to publish from this [doc](./PUBLISH.md).
71-
72-
## Starting from `.net framework 4.x`
73-
In order to adapt to `.net framework 4.x`, we have packaged a nuget package separately, the package name is [`Apache.IoTDB.framework`](https://www.nuget.org/packages/Apache.IoTDB.framework/).
74-
75-
You can install it through Package Manager (PM), .NET CLI, etc. For example (.NET CLI):
76-
77-
```sh
78-
dotnet add package Apache.IoTDB.framework --version 0.12.1.2
79-
```
72+
You can find out how to publish from this [doc](./PUBLISH.md).

README_ZH.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ Apache IoTDB Github: https://github.com/apache/iotdb
3939
dotnet add package Apache.IoTDB
4040
```
4141

42-
请注意,`Apache.IoTDB`这个包仅支持`.net 5.0`。 如果您使用的是`.net framework 4.x`,请参考[`.net framework 4.x`开始](#从-net-framework-4x-开始)
43-
42+
请注意,`Apache.IoTDB`这个包仅支持大于`.net framework 4.6.1`的版本。
4443
## 环境准备
4544

46-
.NET SDK Version == 5.0
45+
.NET SDK Version >= 5.0
46+
.NET Framework >= 4.6.1
4747

4848
## 如何使用 (快速上手)
4949
用户可参考[使用样例](https://github.com/eedalong/Apache-IoTDB-Client-CSharp-UserCase)中的测试代码了解各个接口使用方式
5050

5151

5252
## iotdb-client-csharp的开发者环境要求
53-
.NET SDK Version == 5.0
53+
.NET SDK Version >= 5.0
54+
.NET Framework >= 4.6.1
5455
ApacheThrift >= 0.14.1
5556
NLog >= 4.7.9
5657

@@ -63,13 +64,4 @@ dotnet add package Apache.IoTDB
6364
### 命令行工具
6465

6566
## 在 nuget.org 上发布你自己的客户端
66-
你可以在这个[文档](./PUBLISH.md)中找到如何发布
67-
68-
## `.net framework 4.x`开始
69-
为了适配`.net framework 4.x`,我们单独构建了一个Nuget包,包名是[`Apache.IoTDB.framework`](https://www.nuget.org/packages/Apache.IoTDB.framework/)
70-
71-
您可以使用PM、.NET CLI等工作来安装它。以.NET CLI为例:
72-
73-
```sh
74-
dotnet add package Apache.IoTDB.framework --version 0.12.1.2
75-
```
67+
你可以在这个[文档](./PUBLISH.md)中找到如何发布

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)

src/Apache.IoTDB/DataStructure/SessionDataSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ private bool FetchResults()
251251
try
252252
{
253253
var task = myClient.ServiceClient.fetchResultsAsync(req);
254-
task.Wait();
255-
var resp = task.Result;
254+
255+
var resp = task.ConfigureAwait(false).GetAwaiter().GetResult();
256256

257257
if (resp.HasResultSet)
258258
{

src/Apache.IoTDB/SessionPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SessionPool : IDisposable
3838
private ILogger _logger;
3939

4040
public SessionPool(string host, int port, int poolSize)
41-
: this(host, port, "root", "root", poolSize, "UTC+08:00", 8, true, 60)
41+
: this(host, port, "root", "root", 1024, "UTC+08:00", poolSize, true, 60)
4242
{
4343
}
4444

0 commit comments

Comments
 (0)