Code > General / libs / generic_threads

Informations :

							Project name: Generic Threads
Description: Generic threads libraries (windows mingw / linux)
Date: 06/11/2020
Updated: 06/11/2020
Type: Personnal
Project informations:
- 2 Files
- 0 Folder
- 54 Lines
- 938 Characters
Group:
public

Tags:
Windows
Linux
Threads
COM
C
C++
Makefile
Pthread
										

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