0
#define SHMKEY ((long)12344)
#define SEMKEY ((long)12345)
#define MAXS 10000
#define MAXL 1000

typedef struct{
    int lung;``
    int i;
    char s[MAXS];
}Mesaj;

#define PLUS (sizeof(int))

typedef struct{
    int tip;
    int pid;
    Mesaj mesaj;
} Segment;

#include <string.h>
#include "shmmesaj.h"

struct sembuf s= {0, 1,0}; //clean segment

struct semibuf w= {0,-1,0}; //ocupy segment

void Wait(int semafor) {
    semop(semafor,&w,1);
}

void Signal(int semafor) {
    semop(semafor,&s,1);
}

Mesaj * ReadMes(Segment* segment){
    static Mesaj mesaj;
    mesaj.lung=segment->mesaj.lung;
    memcpy((char*)&mesaj+sizeof(int), (char*)segment+3*sizeof(int), mesaj.lung);
    return &mesaj;
}

void WriteMes(Segment* segment,Mesaj * pm){
    segment->mesaj.lung=pm->lung;
    memcpy((char*)segment+3*sizeof(int),(char*)pm+sizeof(int),pm->lung);
}

main(){}
4

0 回答 0