mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
userland: move some multithreaded examples from cpp-cheat
Using them mostly to evaluate how well the emulators are handling user mode multithreading.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#cpp
|
||||
// https://github.com/cirosantilli/linux-kernel-module-cheat#cpp-multithreading
|
||||
//
|
||||
// The non-atomic counters have undefined values which get printed:
|
||||
// they are extremely likely to be less than the correct value due to
|
||||
|
||||
16
userland/cpp/count.cpp
Normal file
16
userland/cpp/count.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Count to infinity sleeping one second per number.
|
||||
//
|
||||
// https://github.com/cirosantilli/linux-kernel-module-cheat#cpp-multithreading
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
while (1) {
|
||||
std::cout << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
10
userland/cpp/thread_hardware_concurrency.cpp
Normal file
10
userland/cpp/thread_hardware_concurrency.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine
|
||||
//
|
||||
// Not affected by taskset: https://stackoverflow.com/questions/1006289/how-to-find-out-the-number-of-cpus-using-python/55423170#55423170
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
int main() {
|
||||
std::cout << std::thread::hardware_concurrency() << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user