failed sched_getaffinity_threads attempt

Better eigen naming.
This commit is contained in:
Ciro Santilli
2018-07-22 19:54:56 +01:00
parent 787b989df7
commit 0dfbd93afe
4 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-step-debug-multicore */
#define _GNU_SOURCE
#include <assert.h>
#include <pthread.h>
#include <sched.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void* main_thread_0(void *arg) {
int i;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(*((int*)arg), &mask);
sched_setaffinity(0, sizeof(cpu_set_t), &mask);
i = 0;
while (true) {
printf("0 %d\n", i);
sleep(1);
i++;
}
return NULL;
}
void* main_thread_1(void *arg) {
int i;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(*((int*)arg), &mask);
sched_setaffinity(1, sizeof(cpu_set_t), &mask);
i = 0;
while (true) {
printf("1 %d\n", i);
sleep(1);
i++;
}
return NULL;
}
int main(void) {
enum NUM_THREADS {NUM_THREADS = 2};
pthread_t threads[NUM_THREADS];
int thread_args[NUM_THREADS];
pthread_create(&threads[0], NULL, main_thread_0, (void*)&thread_args[0]);
pthread_create(&threads[1], NULL, main_thread_1, (void*)&thread_args[1]);
pthread_join(threads[0], NULL);
pthread_join(threads[1], NULL);
return EXIT_SUCCESS;
}