Home > Net >  C # socket communication data conflict
C # socket communication data conflict

Time:12-25

In the socket communication, several client server connection, with a few colleagues client communications, after receive the data, algorithm processing, in the algorithm has several public List and several variables, multiple threads will not cause data conflict? At the same time for a total of data reading and writing?
Why doesn't work after I lock?

Algorithm is time-consuming, generally at the end of the 2-3 ms can, but some time is too long,

Locking method

CodePudding user response:

How to say, because we don't know whether you have to deal with what,
We can only say "isolation", "channels"

You ask you on a post on the last we stop to reply, because I don't want to say this,
Is accept, computing is computation, display is, you always mix, said in a piece of you said my calculations, I show, affected,
So we can only reply, why do you want to mix in a

This thing, we also not reply, can give you some information, see if you can understand the "isolation", the meaning of the passage

In the beginning, we first do a basic definition, first by way of cor

Tcpclient
Receive data ()
Analytical data ()//IO priority
. The calculated data ()//CPU priority, calculate the ans just calculate, don't change your those public variables
. Display the data ()//UI layer, calculate good, only involves shows, of course, how to show that we don't know your request, we now MVVM or rx moving window, he is to control the DataSource, so itself is also less likely to use what public variables,

In this way, he would have "isolation", then we are using some "parallel" non-blocking, asynchronous way

May use the
1. The rx https://cloud.tencent.com/developer/article/1099766
2. Dataflow https://www.cnblogs.com/dinggf/p/9294613.html
3. Chanel https://www.cnblogs.com/tiger-wang/p/14068973.html

We will hand on the data according to the chain of responsibility level level, but we don't use your synchronous with the lock, they should be parallel, non-synchronous.

Though sp1234 after all opposed to the publish/subscribe it, but I can't get, because I'm a decoupling, but also decrease the difficulty of development, after all, a team is not a person, need some simple point, but also can reduce under the condition of technical requirements, also can finish this task

CodePudding user response:

The most simple change is change the testObject to static member variables,
DataToCloudPoint1 should be a reentrant method,
In fashionable reset lock objects if not global object, your lock is meaningless,
  •  Tags:  
  • C#
  • Related