Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

need help with the following sepcifications

Thread view: 
preethamkumark@yahoo.com - 04 Oct 2006 02:24 GMT
- The program first creates a shared memory buffer containing an array
of 20 integers.
- Each slot of the buffer can have either 0 or 1, where 0 represents an

empty slot, and 1
represents an occupied one.

- Initially, the buffer is empty. Thus, all the slots are initialized
with 0.

- Then the program creates a fan of 2 child processes (producer and
consumer).

- Both processes enter a while loop, and iteratively operate on the
shared buffer in a mutually
exclusive manner.

- use 3 semaphores s, n, and e;

- s: buffer lock (provides mutual exclusion for accessing the shared
buffer)

- n: current number of buffer items (forces consumer to wait when the
buffer is empty)

- e: current number of empty slots (forces producer to wait when the
buffer is full)

- Also, use the buffer index 'in' to let the producer know where to
put
the new item, and index
'out' to let the consumer know where to take an existing item.

- Producer:

- In each iteration, the producer puts a new item (integer 1) to the
buffer. The new item must be placed in the slot next to the end of
occupied items. If the
buffer is already full, then the process is blocked until the consumer
takes at least one item.

- Right after adding a new item, print out the updated contents of the
buffer to stderr  When printing, it must go through a loop, printing
one
character at a time. After printing each character, call usleep(100) to

see if it is interrupted or not (it must not - note that this printing
task must also be
included in the critical section so that it is not interrupted by other
process).

- When printing, specify who's printing (Producer or Consumer). And
the
buffer should be printed out in the following way (note that empty
slots are represented
as dots).
[Producer] 1 1 1 1 1 1 1 . . . . . . . . . 1 1 1 1

- After the printing, call usleep(pro_time) to control the speed of
buffer growing.

- Consumer:

- In each iteration, the consumer takes an existing item (integer 1)
from the buffer. The existing item must be taken from the slot at the
beginning of occupied
items. This is simulated by simply replacing 1 with 0 at the index out.
If the buffer
is already empty, then the process is blocked until the producer puts
at least one item.

- Right after removing an item, print out the updated contents of the
buffer to stderr . When printing, it must go through a
loop, printing one character at a time. After printing each character,
call usleep(100) to
see if it is interrupted or not (it must not - note that this printing
task must also be
included in the critical section  so that it is not interrupted by
other process).

- When printing, follow the convention written above (in Producer
section).

- After the printing, call usleep(con_time) to control the speed of
buffer shrinking.

- Note that since we use a bounded buffer system, the buffer must be
implemented as a circular
buffer (the end of the buffer is connected to the start of the buffer).

- Initially, make con_time three times as long as pro_time, so that the

buffer can be quickly filled (for example, pro_time = 100000, con_time
= 300000). Once it is
filled, switch their speed so that now the consumer can quickly empty
the buffer (then
switch their speed again so that the buffer quickly grows). Repeat this
fill-empty cycle twice, and
then terminate both child processes (when the buffer is empty for the
third time). The parent
process must wait for the termination of both child processes, and then
terminate itself.

- An example printing result could be as follows:

[Parent] Starting...
...
[Producer] 1 1 1 1 . . . . . . . . 1 1 1 1 1 1 1 1
[Consumer] 1 1 1 1 . . . . . . . . . 1 1 1 1 1 1 1
...
[Producer] 1 1 1 1 1 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1
[Producer] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[Consumer] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 . 1 1 1 1 1

...
[Consumer] Two cycles completed. Exiting...
[Producer] Two cycles completed. Exiting...
[Parent] Exiting...
opalpa opalpa@gmail.com opalinski - 04 Oct 2006 02:48 GMT
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ArrayBlockingQueue.html
Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Michael Rauscher - 04 Oct 2006 02:56 GMT
[big snip]

As you need help (and as I don't find a question mark in your posting):

If you have problems to understand these specifications, ask the
author(s). Only the author(s) know(s) what he/they wanted to express by
writing these specifications.

HTH
Michael
Mark Space - 04 Oct 2006 03:01 GMT
> - The program first creates a shared memory buffer containing an array
> of 20 integers.

I forget: which homework assignment is this?

Actually, I'd like to know how to create a shared memory buffer in Java.
 Do you suppose he means just a global static where two threads (not
child processes) can get at it?
Manish Pandit - 04 Oct 2006 05:12 GMT
You probably posted your homework assignment on the wrong group, or
your teacher asked you to implement it in the wrong language. This
doesnt sound like java to me :)

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.