-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix to helgrind error for accessing pending_work_item_count_ptr #395
base: master
Are you sure you want to change the base?
Conversation
/azp run Azure-C-Pal |
Azure Pipelines successfully started running 1 pipeline(s). #Resolved |
@@ -237,7 +237,7 @@ MOCKABLE_FUNCTION(, int, threadpool_schedule_work, THANDLE(THREADPOOL), threadpo | |||
|
|||
**SRS_THREADPOOL_LINUX_07_048: [** If reallocating the task array fails, `threadpool_schedule_work` shall fail and return a non-zero value. **]** | |||
|
|||
**SRS_THREADPOOL_LINUX_07_049: [** `threadpool_schedule_work` shall initialize `pending_work_item_count_ptr` with `NULL` then copy the work function and work function context into insert position in the task array and assign `0` to the return variable to indicate success. **]** | |||
**SRS_THREADPOOL_LINUX_07_049: [** `threadpool_schedule_work` shall copy the work function and work function context into insert position in the task array and assign `0` to the return variable to indicate success. **]** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this recurring and it seems that it is not going away, so shall wait for it. We can discuss in person what the problem is, but I think it is better to deal with it once and for all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Dan,
Thanks for the comments. The changes you are mentioning was done in the old commits on request of other reviewers.
https://github.com/Azure/c-pal/pull/373/files/04ed1648d62fe6742bd7056d17c3a43a8175e18a#r1775937979
Please check above link to see the comments.
Since this story is really to unblock anyone using the old threadpool_schedule_work
or someone facing failing tests, I sent the code review with minimal changes.
Can we address your other comments in the threadpool_create_work_item
work that we will have to do later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nishudeshu The short answer is no, we should address these comments now. Kicking them down the road does not buy us anything and there is a high chance they would remain like this in the code, which would be less than ideal.
Strictly on the 2 points:
-
assign
0
to the return variable to indicate success => I have explained why we think 'shall return 0' is better. Changing this is trivial and we should not spend lots of energy in debating this. I assume you understood the reasoning already in the previous code review, but if that's not the case, I can explain it again. -
The comments about pending_work_item_count_ptr in the code make it clear that even if you fix the current helgrind failure, other issues exist and they will surface again. Let's address them now, when the context is in front of us!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I can do that. I have tagged the previous comments above where I was asked to make the changes since returning 0 or NULL indicates an immediate return which may not be always true in case of a cleanup before return at the end of the code.
- What other issues exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
A comment next to this indicating what it represents would be very good. Refers to: linux/src/threadpool_linux.c:75 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
Honestly speccing this level of detail where we say we set a local variable to a certain value is extreme and not really helping. We want to spec at level of the behavior of the public APIs of the module, not at the internals of variable assignment. We can discuss about it in person tomorrow. Refers to: linux/src/threadpool_linux.c:222 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
What guarantees that between line 223 (when we computed that pending_work_item_count_ptr is not NULL) and line 232 (when we're accessing it), the value of pending_work_item_count_ptr has not changed? Refers to: linux/src/threadpool_linux.c:233 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
We mark with (void) the fact that we ignore on purpose return values in the code. This is one such case where interlocked_decrement returns a value, but we ignore it by design. Refers to: linux/src/threadpool_linux.c:232 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
TRUE us a Windows #define, when using bool one uses true and false (lower case). Refers to: linux/src/threadpool_linux.c:226 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
Here and everywhere applicable. In reply to: 2430570839 Refers to: linux/src/threadpool_linux.c:914 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
At line 223, we are checking if pending_work_item_count_ptr is NULL or not. It is NULL for the In reply to: 2430567049 Refers to: linux/src/threadpool_linux.c:233 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
Done In reply to: 2430565113 Refers to: linux/src/threadpool_linux.c:222 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
Done In reply to: 2430567973 Refers to: linux/src/threadpool_linux.c:232 in d2f4b01. [](commit_id = d2f4b01, deletion_comment = False) |
The pending_work_item_count_ptr is not used when threadpool_schedule_work is used. pending_work_item_count_ptr is always initialized to NULL in threadpool_create and when pending_work_item_count_ptr is initialized to NULL in reallocate task array, an exlusive lock is used. So, removing the NULL assignment in the threadpool_schedule_work.