Hi, this is a simple example:
Code:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void * thread_func(void *arg)
{
for ( ; ; ) {
fputc ('1', stderr);
sleep(1);
}
return NULL;
}
int main()
{
pthread_t thread_id;
if(pthread_create (&thread_id, NULL, thread_func, NULL) != 0) {
fputs("Error: pthread can't be created\n", stderr);
exit(1);
}
for ( ; ; ) {
fputc ('0', stderr);
sleep(1);
}
return 0;
}
gcc -o thread
-lpthread thread.c