-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinkedList: Change assignment order in TLink.remove #247
base: master
Are you sure you want to change the base?
Conversation
|
That change does not make it threadsafe...but less likely to run into a null access.
So it just minimizes risks of that...nothing more.
|
Yeah, it could reduce the risk of that particular crash. But that might actually do more harm than good, because the problem would still there, just harder to notice. |
It won't be worse than before - as the issue is already not overly likely to happen. So I do not see it as "more harm than good". Crashes can still happen, in both cases it is rare to experience it (so hard to spot that there is an issue). So this PR just allows certain scenarios to become kinda threadsafe. |
Well, "kinda thread-safe" still isn't thread-safe, and the more rarely these issues occur, the harder they become to find and fix. |
If execution orders are not guaranteed than switching lines does indeed make not much sense. |
Do you agree that it would be better style (conceptually) to first change the links and then unassign the value? Even if the execution order is not guaranteed, I argue that it would be the correct order which should be reflected in the code. If you consider accepting the PR, I will adapt the commit coment (making it sound less like introducing thread-safety, which I did not want to imply). Otherwise feel free to close the PR. |
When removing a link, change neighbour links before setting the link value to null which is the intuitive order of modifications. Even though LinkedList is not thread-safe and this change does not prevent segmentation faults, it may reduce the chance of null access problems when concurrently modifying and iterating over the list.
6d1fd75
to
ce765cc
Compare
In TVTower, I experience sporadic segmentation faults. Some of them could be traced to null access in the "contains" method of TLinkedList where the link value is compared to the parameter object, but the link value is null. This probably happens because several threads access the same list, concurrently changing and iterating over it.
With this change, the link's value is set to null only after the links of the neighbour nodes have been updated. This reduces the chance of a thread iterating a list currently being modified to look at a link whose value was set to null.