> can you provided a small piece of code that shows this behaviour?

Here's one without error checking.  Be sure to use -pthread.

Peter

--
Peter Dufault ([EMAIL PROTECTED])   Realtime development, Machine control,
HD Associates, Inc.               Fail-Safe systems, Agency approval


#include <unistd.h>

#include <sys/stat.h>
#include <sys/types.h>

#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>

struct threadstuff {
        int rfid, wfid;
        const char *name;
};

static void *
reader(void *arg) {
        struct threadstuff *pts = (struct threadstuff *)arg;

        fprintf(stderr, "Opening %s for read...", pts->name);
        pts->rfid = open(pts->name, O_RDONLY);
        fprintf(stderr, " reader got fid %d.\n", pts->rfid);

        return 0;
}

static void *
writer(void *arg) {
        struct threadstuff *pts = (struct threadstuff *)arg;

        fprintf(stderr, "Opening %s for write...", pts->name);
        pts->wfid = open(pts->name, O_WRONLY);
        fprintf(stderr, " writer got fid %d.\n", pts->wfid);

        return 0;
}

int
main(int ac, char *av[]) {
        pthread_t r, w;
        void *value;

        struct threadstuff ts;

        ts.name =  "./my_fifo";
        ts.rfid = ts.wfid = -1;

        (void)unlink(ts.name);
        (void)mkfifo(ts.name, 0666);

        pthread_create(&r, 0, reader, (void *)&ts);
        pthread_create(&w, 0, writer, (void *)&ts);

        pthread_join(r, &value);
        pthread_join(w, &value);

        if (ts.rfid != -1)
                (void)close(ts.rfid);

        if (ts.wfid != -1)
                (void)close(ts.wfid);

        return 0;
}

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to