dedalqq
2/17/2017 - 9:41 AM

main.c

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>

typedef union {
    char str[4];
    struct {
        char c1;
        char c2;
        char c3;
        char c4;
    };
} tt;


int p[2];


void *handler(void *threadid);

int main(void) {

    tt t;

    strncpy(t.str, "omg\n", 4);

    printf(" -> %c", t.c1);
    printf(" -> %c", t.c2);
    printf(" -> %c", t.c3);
    printf(" -> %c", t.c4);

    int *omg = malloc(sizeof(omg));

    *omg = 123;

    //printf("omg -> : %x", (char)omg);

    int qq[3];

    printf("qq -> %d: \n", (int)sizeof(qq));


    pipe(p);

    pthread_t *threads = malloc(sizeof(pthread_t));

    int q = pthread_create(threads, NULL, handler, NULL);
    //write(1, "1", 3);

    printf("omg1\n");

    write(p[1], omg, 8);
    printf("done\n");
    sleep(100);

    //pthread_exit(NULL);

    free(threads);

    return 0;
}


void *handler(void *threadid) {
    //write(1, "2", 3);

    int *data;

    sleep(2);
    read(p[0], data, sizeof(data));

    printf("data: [%d]\n", *data);
    sleep(100);
    //pthread_exit(NULL);
}