Untitled
unknown
c_cpp
10 months ago
770 B
12
Indexable
#include <iostream>
#include <thread>
#include <vector>
#include <sched.h> // For sched_getcpu()
void function1() {
for (int i = 0; i < 200; i++) {
std::cout << "+";
}
std::cout << "\nThread 1 is running on core: " << sched_getcpu() << std::endl;
}
void function2() {
for (int i = 0; i < 200; i++) {
std::cout << "-";
}
std::cout << "\nThread 2 is running on core: " << sched_getcpu() << std::endl;
}
int main() {
std::thread t1(function1);
std::thread t2(function2);
std::thread::id t1_id = t1.get_id();
std::thread::id t2_id = t2.get_id();
std::cout << "ID of thread 1: " << t1_id << std::endl;
std::cout << "ID of thread 2: " << t2_id << std::endl;
t1.join();
t2.join();
return 0;
}
Editor is loading...
Leave a Comment