sharedMem: Fix race condition and sending uninitialized values to the server #1
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.
Fixes a race condition inside of the
sharedMem.insertmethod. The lock was not being held when the index of the next value was changed, meaning a thread could instantly overwrite the previous value during high contention.Fixes an issue where a default value of
-99.9was being used to indicate an uninitialized field, however thesharedMem.getfunction would check for99.9.I'd also like to note that previously initialized values will still remain inside of the memory, meaning when writing a message with a single value to a field which previously contained 3 values, the
getmethod will think it is a 3 valued field, since the values are never reset and send them over the network. This can be fixed by a later PR.This implementation of a custom shared memory shows how error prone writing custom data structures is. Additionally the shared memory is currently only used to relay messages over TCP once meaning the whole thing could be replaced by a
multiprocessing.Queue. This introduces slight serialization overhead, which should be negligible. Alternativelyqueue.Queuecould be used, since the client uses threads for networking code anyway, not full processes.