main.cpp
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <thread>
void loop(char * data)
{
for (int i = 0; i < 5; ++i)
{
printf("hello from function %d %s \n", i , data);
usleep(10);
}
}
class test
{
public:
void loop(int a)
{
for (int i = 0; i < 5; ++i)
{
printf("hello from class %d\n", i );
usleep(10);
}
}
};
typedef void * (*THREADFUNCPTR)(void *);
main()
{
test t;
pthread_t thread0, thread1;
pthread_create(&thread0, NULL, (THREADFUNCPTR) &test::loop, &t);
pthread_create(&thread1, NULL, (THREADFUNCPTR) loop, (void*) "data");
pthread_join(thread0, NULL);
pthread_join(thread1, NULL);
exit(EXIT_SUCCESS);
}
makefile
#
CC=x86_64-w64-mingw32-g++
CFLAGS=-w
LINKERS=-pthread
all :
$(CC) $(CFLAGS) $(LINKERS) main.cpp -o main