Skip to content

Commit

Permalink
Merge pull request #95 from eedalong/fix/concurrency
Browse files Browse the repository at this point in the history
Modify the issue of premature thread exit caused by Monitor.Wait().
  • Loading branch information
lausannel committed May 22, 2023
2 parents dea6aff + 828bf7e commit d325338
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 44 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.user
*.userosscache
*.sln.docstates
**/tmp

# Build results
[Dd]ebug/
Expand Down Expand Up @@ -65,7 +66,7 @@ publish/


### Rider ###
.idea
/.vs/Apache.IoTDB/FileContentIndex
/.vs/ProjectEvaluation
/.vs/Apache.IoTDB
.idea
/.vs/Apache.IoTDB/FileContentIndex
/.vs/ProjectEvaluation
/.vs/Apache.IoTDB
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ We have prepared Nuget Package for C# users. Users can directly install the clie
dotnet add package Apache.IoTDB
```

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).
Note that the `Apache.IoTDB` package only supports versions greater than `.net framework 4.6.1`.(#starting-from-net-framework-4x).

## Prerequisites

.NET SDK Version == 5.0
.NET SDK Version >= 5.0
.NET Framework >= 4.6.1

## How to Use the Client (Quick Start)

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

```
.NET SDK Version == 5.0
.NET SDK Version >= 5.0
.NET Framework >= 4.6.1
ApacheThrift >= 0.14.1
NLog >= 4.7.9
```
Expand All @@ -67,13 +69,4 @@ NLog >= 4.7.9
### Command Line Tools

## Publish your own client on nuget.org
You can find out how to publish from this [doc](./PUBLISH.md).

## Starting from `.net framework 4.x`
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/).

You can install it through Package Manager (PM), .NET CLI, etc. For example (.NET CLI):

```sh
dotnet add package Apache.IoTDB.framework --version 0.12.1.2
```
You can find out how to publish from this [doc](./PUBLISH.md).
20 changes: 6 additions & 14 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ Apache IoTDB Github: https://github.com/apache/iotdb
dotnet add package Apache.IoTDB
```

请注意,`Apache.IoTDB`这个包仅支持`.net 5.0`。 如果您使用的是`.net framework 4.x`,请参考[`.net framework 4.x`开始](#从-net-framework-4x-开始)

请注意,`Apache.IoTDB`这个包仅支持大于`.net framework 4.6.1`的版本。
## 环境准备

.NET SDK Version == 5.0
.NET SDK Version >= 5.0
.NET Framework >= 4.6.1

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


## iotdb-client-csharp的开发者环境要求
.NET SDK Version == 5.0
.NET SDK Version >= 5.0
.NET Framework >= 4.6.1
ApacheThrift >= 0.14.1
NLog >= 4.7.9

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

## 在 nuget.org 上发布你自己的客户端
你可以在这个[文档](./PUBLISH.md)中找到如何发布

## `.net framework 4.x`开始
为了适配`.net framework 4.x`,我们单独构建了一个Nuget包,包名是[`Apache.IoTDB.framework`](https://www.nuget.org/packages/Apache.IoTDB.framework/)

您可以使用PM、.NET CLI等工作来安装它。以.NET CLI为例:

```sh
dotnet add package Apache.IoTDB.framework --version 0.12.1.2
```
你可以在这个[文档](./PUBLISH.md)中找到如何发布
22 changes: 12 additions & 10 deletions src/Apache.IoTDB/ConcurrentClientQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Return(Client client)
{
Monitor.Enter(ClientQueue);
ClientQueue.Enqueue(client);
Monitor.Pulse(ClientQueue);
Monitor.PulseAll(ClientQueue); // wake up all threads waiting on the queue, refresh the waiting time
Monitor.Exit(ClientQueue);
Thread.Sleep(0);
}
Expand Down Expand Up @@ -52,15 +52,17 @@ public Client Take()
{
Client client = null;
Monitor.Enter(ClientQueue);
if (ClientQueue.IsEmpty)
{
Monitor.Wait(ClientQueue, TimeSpan.FromSeconds(Timeout));
}
if (!ClientQueue.TryDequeue(out client))
{
}
else
{
while(true){
bool timeout = false;
if (ClientQueue.IsEmpty)
{
timeout = !Monitor.Wait(ClientQueue, TimeSpan.FromSeconds(Timeout));
}
ClientQueue.TryDequeue(out client);

if(client != null || timeout){
break;
}
}
Monitor.Exit(ClientQueue);
if (client == null)
Expand Down
4 changes: 2 additions & 2 deletions src/Apache.IoTDB/DataStructure/SessionDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ private bool FetchResults()
try
{
var task = myClient.ServiceClient.fetchResultsAsync(req);
task.Wait();
var resp = task.Result;

var resp = task.ConfigureAwait(false).GetAwaiter().GetResult();

if (resp.HasResultSet)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Apache.IoTDB/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SessionPool : IDisposable
private ILogger _logger;

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

Expand Down

0 comments on commit d325338

Please sign in to comment.