Thread Prog in C language (seg fault)
I am able to create multiple threads and a shared memory segment...
Now I want to write into one block of shared memory (need to divide the single shared memory into multiple blocks) as follows:
blockid, threadid, and data.
For example one single block of a shared memory should contain blockid, threadid and data.
where the blockid will be block1, block2, block3 and so on......
threadid will be thread1, thread2, thread3 and so on....
data will be user input data "string format"
Once I am able to write as above, then I should be in a position to read the data from the reader thread by specifying the threadid and blockid and also if the reader threads want to modify the data, so it can modify the data.
On top of it we need to assure that either of the reader thread or writer thread should access any particular block of shared memory at any instance of time, but not both at a time.
I am sending you the code attached along with this post, could you please help me out.....
Thread Prog in C language (seg fault)
Many many thanks to you for providing hints. But I have no idea/clue that how I'll pass this structure to writer thread, and once I am able to pass this structure to writer thread and the writer thread is able to write some data into it, then again how do I pass this structure to reader thread. "setpshared() is supported on AIX also, but I am sorry to say that don't know how to use it.
Thread Prog in C language (seg fault)
I have created the structure as follows:
Code:
typedef sturct
{
int thread_id;
int block_id;
char string[1024];
}DataBlock;
DataBlock *writeparm;
But my writer fails, it doesn't return after writing. It stops immediately after writing the data and it doesn't pass control to the reader and stops further execution of the program
Thread Prog in C language (seg fault)
"Codeplug"May I have your kind attention please on this. I don't why my writer function is failing.....
One more question I would like to ask on this....
You can continue to use that as an index into the DataBlock array.
When I tried to pass structure variable (DataBlock *writeparm), then I got the compilation error.....
I thought of doing it in differenet way, like passing 2 variable to writer function but that also doesn't work. Right now I am passing one variable in the writer function...
void *writer(void *parm)
I tried this way void *writer(void *parm, char *file), but this gives me lots of lots of error.....
Can we pass 2 variables to writer function, if yes then how can we....
Thread Prog in C language (seg fault)
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.