Skip to content
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

Remove trylock + unlock in acl_reset_condvar() #279

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

IlanTruanovsky
Copy link
Contributor

See #276 for an explanation on why this needs to be done.

In short, assuming library destructors work as we expect (i.e. they do not get called on abort), this code is unnecessary and can introduce undefined behavior.

This will also fix the following Coverity issues:

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:333:3:
  Type: Double unlock (LOCK)

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:332:3:
  1. unlock: "acl_release_condvar" unlocks "cc.waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:375:5:
  1.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:333:3:
  2. double_unlock: "acl_reset_condvar" unlocks "cc.waiter_mutex" while it is unlocked.
lib/acl_threadsupport/src/acl_threadsupport.c:300:5:
  2.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:301:5:
  2.2. destroy: "pthread_mutex_destroy" destroys "C->waiter_mutex".

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:353:3:
  Type: Double unlock (LOCK)

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:345:3:
  1. path: Condition "i < 10000000U /* COUNT */", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:346:5:
  2. path: Condition "0 == i % (1000000U /* COUNT / 10 */)", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:352:3:
  3. path: Jumping back to the beginning of the loop.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:345:3:
  4. path: Condition "i < 10000000U /* COUNT */", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:346:5:
  5. path: Condition "0 == i % (1000000U /* COUNT / 10 */)", taking false branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:351:5:
  6. unlock: "acl_release_condvar" unlocks "cc.waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:375:5:
  6.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:352:3:
  7. path: Jumping back to the beginning of the loop.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:345:3:
  8. path: Condition "i < 10000000U /* COUNT */", taking false branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:353:3:
  9. double_unlock: "acl_reset_condvar" unlocks "cc.waiter_mutex" while it is unlocked.
lib/acl_threadsupport/src/acl_threadsupport.c:300:5:
  9.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:301:5:
  9.2. destroy: "pthread_mutex_destroy" destroys "C->waiter_mutex".

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:477:3:
  Type: Double unlock (LOCK)

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:464:3:
  1. path: Condition "1 != acl_timed_wait_condvar(&cc, 1)", taking false branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:465:3:
  2. path: Condition "1 != cc.timedout[0]", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:465:3:
  3. path: Falling through to end of if statement.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:473:3:
  4. path: Condition "0 != acl_timed_wait_condvar(&cc, 1)", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:473:3:
  5. path: Falling through to end of if statement.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:474:3:
  6. path: Condition "0 != cc.timedout[1]", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:474:3:
  7. path: Falling through to end of if statement.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:475:3:
  8. unlock: "acl_release_condvar" unlocks "cc.waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:375:5:
  8.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:477:3:
  9. double_unlock: "acl_reset_condvar" unlocks "cc.waiter_mutex" while it is unlocked.
lib/acl_threadsupport/src/acl_threadsupport.c:300:5:
  9.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:301:5:
  9.2. destroy: "pthread_mutex_destroy" destroys "C->waiter_mutex".

See intel#276 for an explanation on why this needs to be done.

In short, assuming library destructors work as we expect (i.e. they do not get called on abort), this code is unnecessary and can introduce undefined behavior.

This will also fix the following Coverity issues:
```
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:333:3:
  Type: Double unlock (LOCK)

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:332:3:
  1. unlock: "acl_release_condvar" unlocks "cc.waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:375:5:
  1.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:333:3:
  2. double_unlock: "acl_reset_condvar" unlocks "cc.waiter_mutex" while it is unlocked.
lib/acl_threadsupport/src/acl_threadsupport.c:300:5:
  2.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:301:5:
  2.2. destroy: "pthread_mutex_destroy" destroys "C->waiter_mutex".

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:353:3:
  Type: Double unlock (LOCK)

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:345:3:
  1. path: Condition "i < 10000000U /* COUNT */", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:346:5:
  2. path: Condition "0 == i % (1000000U /* COUNT / 10 */)", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:352:3:
  3. path: Jumping back to the beginning of the loop.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:345:3:
  4. path: Condition "i < 10000000U /* COUNT */", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:346:5:
  5. path: Condition "0 == i % (1000000U /* COUNT / 10 */)", taking false branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:351:5:
  6. unlock: "acl_release_condvar" unlocks "cc.waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:375:5:
  6.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:352:3:
  7. path: Jumping back to the beginning of the loop.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:345:3:
  8. path: Condition "i < 10000000U /* COUNT */", taking false branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:353:3:
  9. double_unlock: "acl_reset_condvar" unlocks "cc.waiter_mutex" while it is unlocked.
lib/acl_threadsupport/src/acl_threadsupport.c:300:5:
  9.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:301:5:
  9.2. destroy: "pthread_mutex_destroy" destroys "C->waiter_mutex".

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:477:3:
  Type: Double unlock (LOCK)

lib/acl_threadsupport/test/acl_threadsupport_test.cpp:464:3:
  1. path: Condition "1 != acl_timed_wait_condvar(&cc, 1)", taking false branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:465:3:
  2. path: Condition "1 != cc.timedout[0]", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:465:3:
  3. path: Falling through to end of if statement.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:473:3:
  4. path: Condition "0 != acl_timed_wait_condvar(&cc, 1)", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:473:3:
  5. path: Falling through to end of if statement.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:474:3:
  6. path: Condition "0 != cc.timedout[1]", taking true branch.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:474:3:
  7. path: Falling through to end of if statement.
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:475:3:
  8. unlock: "acl_release_condvar" unlocks "cc.waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:375:5:
  8.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/test/acl_threadsupport_test.cpp:477:3:
  9. double_unlock: "acl_reset_condvar" unlocks "cc.waiter_mutex" while it is unlocked.
lib/acl_threadsupport/src/acl_threadsupport.c:300:5:
  9.1. unlock: "pthread_mutex_unlock" unlocks "C->waiter_mutex".
lib/acl_threadsupport/src/acl_threadsupport.c:301:5:
  9.2. destroy: "pthread_mutex_destroy" destroys "C->waiter_mutex".
```
Copy link
Contributor

@pcolberg pcolberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @IlanTruanovsky for your detailed exploration! I will wait with the merge until integration passes.

@IlanTruanovsky IlanTruanovsky self-assigned this Feb 17, 2023
@IlanTruanovsky IlanTruanovsky added the bug Something isn't working label Feb 17, 2023
@IlanTruanovsky IlanTruanovsky added this to the 2023.2 milestone Feb 17, 2023
@pcolberg pcolberg merged commit f66baab into intel:main Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question about comment in acl_threadsupport.c regarding design and race conditions
2 participants