The intention of the program. Create N threads with 2 shared memories.
One shared memory to write, one shared memory to recieve.
Consumer creates 2 shared memory to share with producer.
I need H threads for the producer as well(somebody help on it..)
Also another question, would segment_id variable interfere with each other in threads?
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/shm.h>
#include <string.h>
#include <pthread.h>
#define N 10
#define H 20
pthread_t house[N];
struct message
{
char text[10];
int source;
int destination;
};
void *hovig(void *param)
{
struct message m1;
int segment_id;
int segment_id1;
int size = 60;
struct message *shared_memory;
struct message1 *shared_memory1;
segment_id = shmget(IPC_PRIVATE,size,S_IRUSR | S_IWUSR);
shared_memory = (struct message *) shmat(segment_id,NULL,0);
segment_id1 = shmget(IPC_PRIVATE,size,S_IRUSR | S_IWUSR);
shared_memory1 = (struct message *) shmat(segment_id1,NULL,0);
return (void*)(size);
}
int main()
{
int value = 4;
int i = 0;
for(i = 0; i < N; i++)
pthread_create(&house, NULL,&hovig, &(value));
pthread_join(house,NULL);
}