Hello and welcome to Stackoverflow. Your program could be as simple as
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
int x;
void func(void*) {
x++;
printf("x: %d\n", x);
}
int main() {
pthread_t thread1;
if (pthread_create(&thread1, NULL, &func, NULL)) {
perror("Thread creation failed");
};
func(NULL);
pthread_join(thread1, NULL);
}
However what you will get by this is a so called data race or race condition
If you really want to count just something concurrently, then an atomic could be what you need:
#include <stdatomic.h>
atomic_int x;
void func(void*) {
atomic_fetch_add(&x,1);
printf("x: %d\n", atomic_load(&x));
}
Furthermore this default thread should still be suitable, and you could use pthread_attr_setschedpolicy
but I am not sure otherwise please elaborate more.