Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. 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*,

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*,

Scheduled Pinned Locked Moved Managed C++/CLI
helpcssquestion
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11570266
    wrote on last edited by
    #1

    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);

    }

    L 1 Reply Last reply
    0
    • U User 11570266

      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);

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Your declaration of the producer function, does not match the definition required by pthread_create, see http://man7.org/linux/man-pages/man3/pthread_create.3.html[^].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups