multithreading - C++ Threads - pthread_create, pthread_join -


can tell me doing wrong here? implementing pthread_create incorrectly

int iret1 = pthread_create(&producer, null, produce, void*);

int iret2 = pthread_create(&consumer1, null, consume, void*);

#include <iostream> #include <cstdlib> #include <pthread.h> #include <ctime> #include <time.h>  #define empty 0 #define filled 1 #define buffer_size 20  using namespace std;  //prototypes void produce(); void consume(int);  int buffer[buffer_size];  int main() {       int iret1 = pthread_create(&producer, null, produce, null);      //join threads        return 0; } 

if not using thread routine argument, pass null pointer instead of void*:

pthread_create( &producer, null, produce, null ); 

the thread routine supposed of void* ()( void* ) type. yours different. should like:

/// fancy producer thread routine extern "c" void* produce( void* arg ) {      // thing here      return 0; // or if want result in pthread_join } 

also, sleep(3) not greatest way of thread synchronization :)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -