cpp: parametrize nthreads on threaded programs CLI

Mark them as multithreaded in path_properties. Preparation for
https://cirosantilli.com/linux-kernel-module-cheat/#user-mode-static-executables-with-dynamic-libraries
which is likely what breaks gem5 on them.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-11-04 23:00:01 +00:00
parent 425d3a5713
commit 5b67747214
3 changed files with 41 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
//
// On Ubuntu 19.04, they ar large possibly non-consecutive numbers.
#include <cstring>
#include <iostream>
#include <mutex>
#include <thread>
@@ -12,15 +13,30 @@
std::mutex mutex;
void myfunc(int i) {
// Mutex and flush to prevent the output from
// different threads from interleaving.
mutex.lock();
std::cout << i << " " << std::this_thread::get_id() << std::endl;
std::cout <<
i << " " <<
std::this_thread::get_id() << std::endl
<< std::flush;
mutex.unlock();
}
int main() {
int main(int argc, char **argv) {
std::cout << "main " << std::this_thread::get_id() << std::endl;
std::vector<std::thread> threads;
for (unsigned int i = 0; i < 4; ++i) {
unsigned int nthreads;
// CLI arguments.
if (argc > 1) {
nthreads = std::strtoll(argv[1], NULL, 0);
} else {
nthreads = 1;
}
// Action.
for (unsigned int i = 0; i < nthreads; ++i) {
threads.push_back(std::thread(myfunc, i));
}
for (auto& thread : threads) {