Fixed
Created: Apr 12, 2018
Updated: Dec 3, 2018
Resolved Date: May 9, 2018
Found In Version: 8.0.0.24
Fix Version: 8.0.0.26
Severity: Standard
Applicable for: Wind River Linux 8
Component/s: Toolchain
When waiting for a future top shows 100% CPU usage, and strace shows a steady stream of futex calls
[pid 15141] futex(0x9d19a24, FUTEX_WAIT, -2147483648, {4222429828, 3077922816}) = -1 EINVAL (Invalid argument)
You can refer to https://stackoverflow.com/questions/34259429/should-stdfuturewait-be-using-so-much-cpu-is-there-a-more-performant-call for more details on the bug.
The community already created the patches:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68921
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=231679
This is a code example:
#include <future>
#include <iostream>
#include <thread>
#include <unistd.h>
int main() {
std::promise<void> p;
auto f = p.get_future();
std::thread t([&p](){
std::cout << "Biding my time in a thread.\n";
sleep(10);
p.set_value();
});
std::cout << "Waiting.\n";
f.wait();
std::cout << "Done.\n";
t.join();
return 0;
}
1. Build this example test:
g++ --std=c++11 -Wall -g -o spin-wait spin-wait.cc -pthread
2.execute the binary spin-wait
./spin-wait &
3.execute the top command
During the sleeping time, the cpu usage won't be 100%.