Dear All,

I need to implement the below mentioned features in my program attached. Any 
clue or hint about how to proceed....


Imagining that there are four threads - 2 writers and 2 readers and we have one 
shared memory 
segment with one block in it. 

All threads are contending for the same block of shared memory.
The Writers will write just one message each and the readers will attempt to 
read, process and respond.
A typical run would look like this :-

1.Writer 1 & Writer 2 read in a unique buffer from two different files and 
store these  in malloced blocks of memory. 

2. Writer 1 contends for the shared memory segment with the other 3 threads and 
if he get it - locks the segment.

3. Writer 1 writes the message to the segment along with a header defining the 
length of the buffer
he has written,his thread ID, and a flag showing it is an 'inbound' operation 
and then appends the 
buffer he has read from file. 
He then unlocks the segment. And immediately starts polling  to get back a 
response.

4. Reader 1 or Reader 2 contend to read from shared memory. Reader 1 wins the 
race and locks the block

5. Reader 1 reads in the buffer, parses the header to make sure it is a 
'inbound' request, 
        IF  it is a 'inbound' requests  he reads in the message as defined by 
length field in the header 
                     then xors the buffer or rot13's the buffer and moves to 
point 6.  
                ELSE He unlocks the buffer because it's not an inbound request.

6. Reader 1 then clears that block of shared memory and writes back a header 
which has in it
    The threadid of the sender, the length of the xor'd or rot13'd buffer and a 
flag indicating it is a 'outbound' operation.
     He the writes the buffer onto the back of this and unlocks the shared 
memory block.

7. Writer 1 is polling for a response. He wins the race with the other 3 
threads and locks the block.
     He peaks into the shared memory and reads the header.
     IF the operation is 'outbound' i.e from a reader thread and the threadid 
is his then he moves to point 8.
     ELSE he unlocks the blocks because it is not a response for him and or it 
is an 'inbound' request from Writer 2.

8. Writer 1 xors or rot13's the response message and then compares it with the 
message he sent which he stored in 
    malloced memory in point 1.
    IF it matches he signals success by writing a suitable message to standard 
out.
    IF it doesn't he writes the block to a error file along with the block he 
sent and exits the process witn a suitable error code and 
    error message to standard error.

When both writer 1 and writer 2 have written their message, got back a response 
and check it is correct.

Of course all of this is happening at once. So writer 1 and writer 2 are both 
trying to lock the blocks and send 'inbound' messages
and readers 1 and readers 2 are simultaneously trying to lock the same block to 
read from it, process the message and respond.


skumar

[Non-text portions of this message have been removed]

Reply via email to