Spinroot

A forum for Spin users

You are not logged in.

#1 2015-01-26 03:55:47

Dharma
Member
Registered: 2011-09-21
Posts: 13

modex - compilation error

Hi,
I'm trying the following C program but Modex is complaining.

    Extract Model:
    ==============
modex prod_cons_two_signals.c
MODEX Version 2.7 - 1 January 2015
created: model and _modex_.run

    Compile and Run:
    ================
sh _modex_.run
spin: model:66, Error: undeclared variable: get    saw ''(' = 40'
---


The following C program uses get() and put(int). They both are externally defined in another file. I put %O put_get.o in my prx file. That's the only thing in my prx file.

/* 1 producer; 2 consumers; two signals (fill, empty) */

#include <pthread.h>
#include <assert.h>

pthread_mutex_t mutex;
pthread_cond_t empty;
pthread_cond_t fill;

extern int count;
extern int get();
extern void put(int);


void *producer(void *arg) {
   int i;
   while(1) {
      pthread_mutex_lock(&mutex);
      while (count == 1)
        pthread_cond_wait(&empty, &mutex);
      put(i);
      pthread_cond_signal(&fill);
      pthread_mutex_unlock(&mutex);
   }
}


void *consumer(void *arg) {
    int i;
    while(1) {
       pthread_mutex_lock(&mutex);
       while(count == 0)
         pthread_cond_wait(&fill, &mutex);
       int tmp = get();
       pthread_cond_signal(&empty);
       pthread_mutex_unlock(&mutex);
    }
}


void main()
{
   pthread_t t1, t2, t3;
   pthread_mutex_init(&mutex, NULL);
   pthread_cond_init(&fill, NULL);
   pthread_cond_init(&empty, NULL);

   pthread_create(&t1, NULL, producer, NULL);
   pthread_create(&t2, NULL, consumer, NULL);
   pthread_create(&t3, NULL, consumer, NULL);

   pthread_join(t1, NULL);
   pthread_join(t2, NULL);
   pthread_join(t3, NULL);
}

Offline

#2 2015-01-27 00:05:05

Dharma
Member
Registered: 2011-09-21
Posts: 13

Re: modex - compilation error

Never mind. I managed to fix it.

Offline

Board footer

Powered by FluxBB