Multi reading needs to be mutex lock #250
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During develop my application, I think I found a defect. It was about reading method from plc.
I have a plc connection instance. I am trying to read values from plc in different intervals with different tag groups.
Each my tag groups has different tags and they have different intervals.
For example, my first read attempt is with 500 plc tags in 500 ms . Other one is with 1000 plc tags in 1000 ms.
if I try these groups reading one by one, everything is good. But when I started both of them. Some time they were getting conflicted.
I mean during one of them was reading values, other one was trying to get values before the process was end. And when this case occurs a few plc tag values returns null.
See sample flowing of my application with conflict.
Reading of taggroup1 is started,
Reading of taggroup1 is ended.
Reading of taggroup2 is started,
Reading of taggroup2 is ended.
**Reading of taggroup1 is started,
Reading of taggroup2 is started, ( before taggroup1 reading process is ended.)**
Reading of taggroup1 is ended.
Reading of taggroup2 is ended.
As you see, they are started one after another in short time. In my opinion first one is started and it is not finished yet. And the other one was calling same code lines in read method.
I added "locking' to reading method. Now all is fine. I have never getting null value. Locking provides us to ensure that only one thread at a time executes a critical section of code at a time.