473,387 Members | 1,790 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,387 software developers and data experts.

can you do this?

1
hi all

i want a help about my project
this is the discribtion:

Description
This assignment is to be done individually. You are to implement a multi-threaded solution for the bounded buffer producer-consumer problem. There will be one producer thread and multiple consumer threads. The items in the buffer will be inter values. The producer thread will produce (get) the buffer items by reading integers from standard input (stdin) and putting them into the buffer. The consumer threads will consume the buffer items by taking the them from the buffer and printing the integer being consumed. Use a Pthreads mutex lock for mutual exclusion and POSIX semaphores for synchronizing the number of full and empty buffers.
The producer thread should print a message for each item produced, showing the integer value and the slot number where it was placed in the buffer. The consumer threads should print a similar message for each integer consumed in addition to the thread ID that consumed the integer.

2. Implementation
2.1 Source Files
You should implement your program with two separate C language source files. The two source files will be separately compiled, and then the object files will be linked together to create a single executable module. The first source file should be named assign3.c. It will contain the code for the main thread, along with any necessary initialization and cleanup operations. The second file should be named prod_cons.c. It will contain the code for the producer thread routine and the consumer thread routine. The prod_cons.c file could also contain functions for initialization and cleanup that are called from the main program, if that seems the appropriate way to design the program. You will also have a header file named assign3.h which can be included in both assign3.c and prod_cons.c.

2.2 Creating and Terminating Threads
The main thread should create one producer thread and multiple consumer threads. The number of consumer threads that will be created should be controlled by defining a symbolic constant NUM_CONSUMERS. Compile and test your program with different values of NUM_CONSUMERS. When you submit your program for grading use a value of 5 for NUM_CONSUMERS.
The producer thread should terminate itself via pthread_exit() when it reaches end-of-file on the input file. The consumer threads will not be able to determine when to exit, so the main thread should sleep for 5 seconds after the producer thread terminates, and then cancel the consumer threads via pthread_cancel().
After all created threads have terminated or been cancelled, the main() thread terminates with a valid return (status) code.



2.3 Shared Memory
To simplify coding, it is recommended that you use global variables for sharing memory for the synchronization variables among the threads. By using global variables, it should not be necessary to pass any parameters to the producer routine. The parameters that need to be passed to the consumer routines is an integer specifying the number of the consumer thread (i.e., 1, 2, 3, etc.). The consumers will use the thread number passed to them to be used as an identifier in output messages from the thread.
When a global variable is used in a program that is created with multiple source files, only one of the source files that reference the variable should contain a declaration for the variable that causes storage to be allocated. The other source files that reference the global variable must declare the variable with the extern attribute. For example:
mod1.c mod2.c
int globvar; extern int globvar;
In this example, storage for globvar is allocated in mod1, and in mod2 it is declared as an external variable that is allocated in some other module (in this case, mod1.c).

2.4 Mutex Lock and Semaphores
Use a Pthreads mutex lock for mutual exclusion, and POSIX unnamed semaphores to synchronize full and empty buffer slots. The pthread_mutex_init(), pthread_mutex_destroy(), pthread_mutex_lock(), and pthread_mutex_unlock() functions are used to manipulate a Pthreads mutex lock. The sem_init(), sem_destroy(), sem_wait(), and sem_post() functions are used to manipulate POSIX semaphores. See examples in the textbook on pages 239-240.
2.5 Other Issues

a) Define the bounded buffer with 10 slots.


b) Insert a random sleep (using sleep() system call) period of 0-2 seconds between each item produced in the producer thread, and between each item consumed in the consumer threads. Use srand(getpid()) to seed the random number generator, and rand()%3 to generate random numbers in the range 0-2.



c) For all system functions referred to above, there are Unix man pages that describe their operation. Refer to the man pages to get detailed descriptions for each function. For example, execute the command: man pthread_exit to see the description of the function.

d) Get started on the assignment early and ask questions in class if you have some. You can bet that others in the class also have similar questions.

________
plz help me soon
May 10 '07 #1
1 1342
Killer42
8,435 Expert 8TB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR
May 11 '07 #2

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

Similar topics

4
by: James | last post by:
I have a from with 2 fields: Company & Name Depening which is completed, one of the following queries will be run: if($Company){ $query = "Select C* From tblsample Where ID = $Company...
5
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to...
2
by: Nick | last post by:
Can someone please tell me how to access elements from a multiple selection list? From what ive read on other posts, this is correct. I keep getting an "Undefined variable" error though... Form...
2
by: Alexander Ross | last post by:
I have a variable ($x) that can have 50 different (string) values. I want to check for 7 of those values and do something based on it ... as I see it I have 2 options: 1) if (($x=="one") ||...
0
by: Dan Foley | last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks for any help out there on how i can make it faster (it might take up to 5 min to write these 3 export files whith 15 records...
5
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
5
by: christopher vogt | last post by:
Hi, i'm wondering if there is something like $this-> to call a method inside another method of the same class without using the classname in front. I actually use class TEST { function...
6
by: Phil Powell | last post by:
Ok guys, here we go again! SELECT s.nnet_produkt_storrelse_navn FROM nnet_produkt_storrelse s, nnet_produkt_varegruppe v, nnet_storrelse_varegruppe_assoc sv, nnet_produkt p WHERE...
1
by: Michel | last post by:
a site like this http://www.dvdzone2.com/dvd Can you make it in PHP and MySQL within 6 weeks? If so, send me your price 2 a r a (at) p a n d o r a . b e
11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.