Fix endianness issue which fixes deadlock#88
Fix endianness issue which fixes deadlock#88pranavkaruvally wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
The change should be to |
|
Hi! I've signed the CLA now. Could someone please take a look at this when you have a chance? Thank you! |
|
Hi! Can you please mention if I need to make any changes or give any more clarifications so that it would more easier to review and validate these changes? |
Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1121387
The threadpool having 8 threads, 1 thread was doing the actual work while the other 7 threads were waiting until the thread which was doing the work becomes available again (Waiting for the number of active threads to change). So, the following line that the main thread was executing contained the issue:
threadpool->work_is_doneis of type_Atomic unsigned longand inside the functionfutex_wait, the variable is directly passed tosyscall(SYS_futex, address, val, ...)where the address was expected to haveuint32_t*.Although, the
threadpool->work_is_donehad a value of1, reading the upper 32-bits made it wait (andwork_is_donehas value0) and hence waits. Originally, this thread should not have blocked, should have proceeded further and should have calledfutex_wake_all to awaken the other7threads which were waiting for the completion of this thread's execution.And, looking back at older commits,
pthreadpool_atomic_uint32_tused to be_Atomic(uint32_t)oruint32_tdepending on the compiler (conditional compilation). On a specific commit it was decided to use thestdatomic.hheader file to replace this and usedtypedef atomic_uint_fast32_t threadpool_atomic_uint32_tinstead.And
atomic_uint_fast32means: an atomic, unsigned integer that is at least 32 bits and chosen for fast hardware access. Hence it is not necessarily 32-bit on every machine, on the contrary is 64-bit on most machines. Changing that to least32_t guarantees it to have 32-bits on all machines that support a 32-bit wide integer type (All linux machines I suppose).