Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


I need help with the following lab. Can anyone explain it to
me on how to approach this problem. Coding would be great
too !!!
No busy waiting allowed. Remember that Java monitors are
'signal and continue'. The input data is called the database
(DB). In this problem, it consists of a single variable
initialized in the main thread, to contain the current time
of day in HH:MM:SS:mmm format (mmm is milliseconds)
truncated to 3 digits. Threads follow these rules:
1. Readers may all attempt to read at the same time, but NOT
if a writer is writing (i.e.; the writer is in the monitor.
2. Writing is exclusive (only 1 writer at a time, no readers
while writing).
3. Options: (to be specified by instructor)
a. Readers have absolute priority over writers.
b. Writers have absolute priority over readers
c. When a reader arrives and a writer is waiting, the reader
is suspended behind the writer instead of being admitted
immediately. Thus, a writer waits for readers that were
running when it arrived, but does not to wait for new readers.

You may program this in C++ or Java. There are 4 controlling
input values:
1. r – number of readers
2. w – number of writers
3. R – delay for a reader to restart
4. W – delay for a writer to restart
Create the following program consisting of 1 main process
(your main program) with n threads:
1. The main thread:
a. Creates the 'n' threads needed. Of these, r of them are
readers and w of them are writers. Starts all readers and
writers.
b. Waits for all 'n' threads to complete. You may use any
method to detect when they are all complete.
c. Prints out the resulting outputs from the threads.
2. Threads:
a. When a thread starts to run, it immediately tries to
enter the monitor.
b. A reader thread reads the DB, outputs the exact message
below, then exits:
>>> DB value read =: HH:MM:SS:mmm by reader number: rr
where the underlined text is replaced with actual data.
c. A writer thread updates the DB with a new value (from the
system time), outputs the exact message below, then exits:
*** DB value set to: HH:MM:SS:mmm by writer number: ww
where the underlined text is replaced with actual data.
d. Each thread accesses the data a total of 10 times,
exiting, then re-entering the monitor after each access.

Hints:
1. File access *might* not be thread-safe, so you should be
prepared to handle this. Read the documentation for the
language you are using.
2. Suggested values for delays are:
a. If looping, R >=1,000,000 and W>=100,000
b. If using “sleep”, then R=100 ms, W=50 ms.

Additional:
• Thread output is to ONE file used by ALL threads (so you
need to synchronize access to it).
• Readers must provide sufficient delay that results are
useful (delay by R before re-trying). R is another input value.
• Writers must also delay. Delay by W, updating the DB each
time. W is an input.
• Test your program with AT LEAST TWO different sets of
values for r and w (#s of readers and writers) plus this
set: r = 4, w=2.

Basic operation of a thread: attempt to enter the monitor.
If unsuccessful, you get put on a queue. When you get in,
read or write the data (depending on type of thread), exit
the monitor, wait the required delay amount, then try again.
Repeat 10 times.


No Answer is Posted For this Question
Be the First to Post Answer

Post New Answer

More C Interview Questions

The file stdio.h, what does it contain?

0 Answers  


inline function is there in c language?

4 Answers  


PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE

0 Answers  


Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?

0 Answers  


How can I manipulate strings of multibyte characters?

0 Answers  


Is it possible to execute code even after the program exits the main() function?

0 Answers  


Discuss the function of conditional operator, size of operator and comma operator with examples.

0 Answers   TCS,


What are the primitive data types in c?

0 Answers  


Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child

10 Answers   IBM, Infosys,


Topics: Structures, Arrays, Searching and Sorting Assume there is a small mobile computer device including a hard disk and a slot for a memory card. The device shall be used to backup photos e.g. during holiday. Every time a memory card is connected all photos of the card are copied into a new folder automatically. And your task is to develop some basic controlling software to show, add, remove, search and sort the directories of photos. Step by Step Implementation 1.Define two symbolic constants, one to hold the total volume of the disk (e.g. VOLUME) and another one to hold the number of entries the files system of the device can handle (MAXFOLD). 2.Define a new structure data type named DATE to store a date consisting of year, month and day as unsigned values. 3.Define an other structure data type FOLDER to store the information of one folder of photos: &#9702;A title as character array of appropriate length &#9702;The location (event) the photos are taken as character array of appropriate length &#9702;The date of the day the photos are copied to the disk using the just defined data type DATE &#9702;The number of photos as natural number &#9702;And the size of the folder in MB as floating point value 4.Define the following global variables and initialise them: &#9702;disk as an array with MAXFOLD elements of data type FOLDER &#9702;folders as natural value to count the number of folders currently stored at the disk (valid elements in the array) TEST: Now you should be able to compile the code the first time without any warning or error. In the menu only "p" to print and "q" to quit will work!. 5.Now complete the functions given by their prototype: float freeSpace ();The function has to calculate the sum of the size component of all elements currently stored in the disk array. The function shall return the free space of the disk by the difference between the available total volume and the calculated sum. TEST: To test this function you only need to uncomment printing the "statusline" at the function actionmenu(). Compare the calculated value with a manual calculation of the example values given above. unsigned isBefore (DATE, DATE);The function checks if one date is before the other. There are 3 different possibilities which have to be handled. Imagine for example these 3 different combinations of values: &#9702;2010-01-01 : 2010-01-02 &#9702;2010-01-01 : 2010-02-01 &#9702;2010-01-01 : 2009-01-01 The function shall just return the result of the comparison. unsigned isEqual (DATE, DATE);The function checks if one date is equal to the other, all components have to be compared. The function shall just return the result of the comparison. int findByDate (DATE);As the array is should be kept in order (sorted by date) implement a binary search for a folder by its date here. You need only to adapt the binary search we used in the exercise. Use the 2 comparing functions above where appropriate. The function shall return the index of the element which was found or -1. TEST: Now you can try searching a folder by date via the "s" in the menu. Activate the corresponding part in the main function. int isSpaceLeft (FOLDER);This function compares the free space of the disk with the size of folder given with the parameter list. The function shall return 1 if there is enough space to add the folder, otherwise 0 (just the result of the comparison). void SortByDate ();This function shall implement the InsertionSort using the component date as key. Use the provided algorithm/souce code of the exercise as template. If you need a comparison between dates, use the function isBefore you have written again. void addFolder (FOLDER);The function has to check if the disk has additional capacities to add the new folder (number of folders and space left). If at least one of these conditions is false print an error message and return -1. Else there has to be added an other test to avoid 2 folder elements with the same date (use the findByDate function here. If there is no folder with the new date simply attach the new folder at the end of the array and call the sorting algorithm afterwards to keep the order in the array. TEST: Now you can try to add a folder via the "a" in the menu. Activate the corresponding part in the main function. void delDir (int);This function removes one element of the disk array. The input parameter contains the index of the element to delete. Deletion can simply be done by moving all elements at the right one to the left (overwriting the element to delete. The function may get a -1. This has to be checked first (certainly there is nothing to delete then!) Don't forget to decrement the counter of elements at the end. TEST: Now you can try to remove a folder by date via the "r" in the menu. Activate the corresponding part in the main function. unsigned findAllOfLocation(char[], FOLDER[]);This is an optional additional task: The function shall find all elements with the given value for the component location (first input parameter). The array elements which are found have to be added to the FOLDER array (second input parameter). As this parameter is an array we can use the result later in the main function. There kernel of function implements a modified linear search on the disk array (it does not stop if one element is found bat continues search until the location of all elements is checked). The finally function shall return the number of elements found in the disk array. TEST: Now you can try to add a folder by date via the "l" in the menu. Activate the corresponding part in the main function.

0 Answers   Siemens,


Why is c known as a mother language?

0 Answers  


What is difference between stdio h and conio h?

0 Answers  


Categories