consumer.C: In function âint main(int, char**)â: consumer.C:69: error: invalid conversion from âvoid (*)(buffer_t*, char)â to âvoid* (*)(void*)â consumer.C:69: error: initializing argument 3 of âint pthread_create(pthread_t*, const pthread_attr_t*,
-
I've been getting this error when I compile in my Consumer/Producer Multi-threaded program. Can someone please help me :)? Here is my code
#include <iostream>
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
#include<complex>define BSIZE 10
define NUM_THREADS 5
using namespace std;
typedef struct {
char buf[BSIZE];
int occupied;
int nextin;
int nextout;
pthread_mutex_t mutex;
pthread_cond_t more;
pthread_cond_t less;
} buffer_t;buffer_t buffer;
void producer(buffer_t *b, char item)
{
pthread_mutex_lock(&b->mutex);while (b->occupied >= BSIZE)
pthread_cond_wait(&b->less, &b->mutex);assert(b->occupied < BSIZE);
b->buf[b->nextin++] = item;
b->nextin %= BSIZE;
b->occupied++;
pthread_cond_signal(&b->more);pthread_mutex_unlock(&b->mutex);
}char consumer(buffer_t *b)
{
char item;
pthread_mutex_lock(&b->mutex);
while(b->occupied <= 0)
pthread_cond_wait(&b->more, &b->mutex);assert(b->occupied > 0);
item = b->buf[b->nextout++];
b->nextout %= BSIZE;
b->occupied--;pthread_cond_signal(&b->less);
pthread_mutex_unlock(&b->mutex);return(item);
}int main(int argc, char* argv[] )
{pthread_t ptid;
pthread_attr_t attr;pthread_attr_init(&attr); /* initialize attr with default attributes */
pthread_create(&ptid, &attr, producer , NULL);}
-
I've been getting this error when I compile in my Consumer/Producer Multi-threaded program. Can someone please help me :)? Here is my code
#include <iostream>
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
#include<complex>define BSIZE 10
define NUM_THREADS 5
using namespace std;
typedef struct {
char buf[BSIZE];
int occupied;
int nextin;
int nextout;
pthread_mutex_t mutex;
pthread_cond_t more;
pthread_cond_t less;
} buffer_t;buffer_t buffer;
void producer(buffer_t *b, char item)
{
pthread_mutex_lock(&b->mutex);while (b->occupied >= BSIZE)
pthread_cond_wait(&b->less, &b->mutex);assert(b->occupied < BSIZE);
b->buf[b->nextin++] = item;
b->nextin %= BSIZE;
b->occupied++;
pthread_cond_signal(&b->more);pthread_mutex_unlock(&b->mutex);
}char consumer(buffer_t *b)
{
char item;
pthread_mutex_lock(&b->mutex);
while(b->occupied <= 0)
pthread_cond_wait(&b->more, &b->mutex);assert(b->occupied > 0);
item = b->buf[b->nextout++];
b->nextout %= BSIZE;
b->occupied--;pthread_cond_signal(&b->less);
pthread_mutex_unlock(&b->mutex);return(item);
}int main(int argc, char* argv[] )
{pthread_t ptid;
pthread_attr_t attr;pthread_attr_init(&attr); /* initialize attr with default attributes */
pthread_create(&ptid, &attr, producer , NULL);}