473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

My program does NOT compile please help

hello,

I have to do the program for the bounded buffer problem in UNIX C and what I have so far is the following code

Expand|Select|Wrap|Line Numbers
  1. #include"genSema.h"
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4. #include<pthread.h>
  5. #include<sys/types.h>
  6. #include<sys/times.h>
  7. #include<unistd.h>
  8.  
  9. int itCount=100;
  10. int N;
  11. int P_RAND_SEED = 1234;
  12. int C_RAND_SEED = 1234;
  13. #define FALSE 0;
  14. #define TRUE 1;
  15. int runFlag = TRUE;
  16. gen_semaphore *full;
  17. gen_semaphore *empty;
  18. void *producer(void *wp);
  19. void *consumer(void *wp);
  20.  
  21. struct buffer_t{
  22.        int buffer[10];
  23.        unsigned int nextFull;
  24.        unsigned int nextEmpty;
  25.  
  26. }widgets;
  27.  
  28. void* producer(void *wp)
  29. {
  30.        char *message1;
  31.        message1 = (char *)wp;
  32.        printf("%s ", message1);
  33.        int runFlag = TRUE;
  34.        int timeToProduce=100000;
  35.        int itCount;
  36.        struct buffer_t *widgPtr;
  37.        widgPtr = (struct buffer_t *)wp;
  38.        srand(P_RAND_SEED);
  39.        itCount=100;
  40.        while(runFlag) {
  41.              usleep(rand()%timeToProduce);
  42.              P(empty);
  43.              if((widgPtr->nextEmpty + 1)%N == widgPtr->nextFull)
  44.                continue;
  45.              widgPtr->buffer[widgPtr->nextEmpty] = itCount++;
  46.              widgPtr->nextEmpty = (widgPtr->nextEmpty+1) % N;
  47.              V(full);
  48.        }
  49.       printf("Producer: Terminating\\n");  
  50. }
  51.  
  52. void* consumer(void *wp)
  53. {
  54.        char *message2;
  55.        message2 = (char *)wp;
  56.        printf("%s ", message2);
  57.        int itCount;
  58.        int timeToConsume=100000;
  59.        struct buffer_t *widgPtr;
  60.        widgPtr = (struct buffer_t *) wp;       
  61.        srand(C_RAND_SEED);
  62.        int runFlag = TRUE;
  63.        while(runFlag) {
  64.           P(full);
  65.           itCount = widgPtr->buffer[widgPtr->nextFull];
  66.           widgPtr->nextFull = (widgPtr->nextFull+1) % N;
  67.           usleep(rand()%timeToConsume);
  68.           V(empty);
  69.       }
  70.      printf("Consumer: Terminating\n");
  71. }
  72.  
  73. main()
  74. {
  75.        int runTime = 2;
  76.        int i;
  77.        pthread_t prod_thrd;
  78.        pthread_t cons_thrd;
  79.        char *message1 = "producer running";
  80.        char *message2 = "consumer running";
  81.        empty = create_gen_semaphore(N);
  82.        full = create_gen_semaphore(0);
  83.        widgets.nextEmpty = 0;
  84.        widgets.nextFull = 0;
  85.        for(i = 0; i < N; i++)
  86.           widgets.buffer[i] = empty;
  87.        pthread_create(&prod_thrd, NULL, producer, message1);
  88.        printf("consumer created at main");
  89.        pthread_create(&cons_thrd, NULL, consumer, message2);
  90.        printf("producer created at main");
  91.        sleep(runTime);
  92.        runFlag = FALSE;
  93.        delete_gen_semaphore(empty);
  94.        delete_gen_semaphore(full);
  95.        printf("Main thread: Terminated\\n");
  96.        exit(1);
  97. }
now, the error I'm getting when compiling the code is the following:


Expand|Select|Wrap|Line Numbers
  1. $ gcc -o prodcons prodcons.c
  2. prodcons.c: In function `main':
  3. prodcons.c:86: warning: assignment makes integer from pointer without a 
  4. cast
  5. Undefined                       first referenced
  6.  symbol                             in file
  7. P                                   /var/tmp//cc6O6sjK.o
  8. V                                   /var/tmp//cc6O6sjK.o
  9. create_gen_semaphore                /var/tmp//cc6O6sjK.o
  10. delete_gen_semaphore                /var/tmp//cc6O6sjK.o
  11. ld: fatal: Symbol referencing errors. No output written to prodcons
  12. collect2: ld returned 1 exit status

Please does anyone know what is that mean and why I'm getting this error. Another this that I would like to let you know about is that in the explanation for the code they tell you that "your job is to define all the italicized functions for thread management and syncronization."

of course the italicized functions are (create_gen_semaphore, delete_gen_semaphore, P, V)
Oct 25 '08 #1
3 1695
Banfa
9,065 Expert Mod 8TB
The first error is on line 86, have you examined that line? Could you describe what you think it is doing?

The other errors are because you have not implemented the functions that you are supposed to implement for you assignment.

And finally what is the purpose of your variable N, it is used in many places but never has a value assigned to it.
Oct 25 '08 #2
well I have looked at the error and that is why I'm asking here because I dont know what is the problem with line 86!!!

The other thing is that I dont know what do you mean about my functions? like I didnt declare them? or what? and I dont know what to assign for N to be honest...
Oct 25 '08 #3
Banfa
9,065 Expert Mod 8TB
well I have looked at the error and that is why I'm asking here because I dont know what is the problem with line 86!!!
What were you trying to do with that piece of code?

The other thing is that I dont know what do you mean about my functions? like I didnt declare them? or what? and I dont know what to assign for N to be honest...
No it looks like you declared them but it looks like they are not defined anywhere.

Your program is not going to work if you don't assign something to N. It sounds like you are trying to write your program without having a good idea of what it is meant to be doing.
Oct 25 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
14
by: Peter Williams | last post by:
Hi All, I am attempting to reverse-obsfuscate an IOCCC entry, and my ultimate goal is to convert the code into Delphi (OO Pascal). I don't understand what the question-mark (?) operator, and...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
3
by: wongjoekmeu | last post by:
Hiya all, I have a strange problem. I have compiled a program with g++ compiler. It seems to compile fine. I can even compile it with debug (-g) option. However at the very beginning when I run...
14
namcintosh
by: namcintosh | last post by:
Hello, everyone. Well, let me cut to the chase and explain my problem. I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight...
4
by: Billy | last post by:
Hi! I'm using: -Compiler: Borland Command Line C++ Compiler 5.5.1 -Code Editor: SciTE 1.75 Anybody know how we can in Scite with command Tools|Go (F5) compile and run my c or cpp program at...
87
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2,...
3
by: kr151080 | last post by:
I need some help with a Measurement Program I Wrote.....I have this code as the main workings of my program: import java.util.*; public class Measurement{ { static Scanner console = new...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.