I am trying to divide the shared memory into multiple blocks in such a way that
Problem 1:
writer thread1 should write into first block of shared memory and another thread reader thread1 should read and modify the date by referring to a particular block of shared memory
Attempt which I made:
I have created a structure as follows and using that structure pointer trying to write some data into shared memory, and with another structure pointer variable I am trying to read the data. But both the reader and writer failing and the reason is not known to me. Please provide me some input on this
Code:
typedef struct{
int block_id;
int thread_id;
char string[1024];
}DataBlock;
DataBlock* writeparm;
DataBlock* readparm;
Please see the writer.c file and reader.c file in the attachment.
Problem 2:
I am trying pass one more variable to reader and writer functions in reader and writer file but this also fails, as of now I am passing only one variable to these functions as parameters.
Code:
void *reader(void *);
void *writer(void *);
What I am trying to attempt:
If I am able to pass two variables to both these function then other variable I can use as a file pointer and hopefully that may sort out the problem, but this also gives me strange kind of error. This is what I am trying to do
Code:
void *reader(void *, void *);
void *writer(void *, void *);
But when I tried this I couldn't succeed... Please give some on this also.
P.S-: I have attached the code (shmem.zip), please have a look at it.