Skip to content

Instantly share code, notes, and snippets.

@dedalqq
Created February 17, 2017 09:41
Show Gist options
  • Save dedalqq/c2e98c8de71dfa50f01492c84e95daa1 to your computer and use it in GitHub Desktop.
Save dedalqq/c2e98c8de71dfa50f01492c84e95daa1 to your computer and use it in GitHub Desktop.
#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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment