Advertisement
Guest User

SO code example

a guest
Apr 20th, 2013
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<pthread.h>
  4. #include<sys/stat.h>
  5. #include<sys/types.h>
  6. #include<fcntl.h>
  7.  
  8. #define BUFF_READ 1024;
  9.  
  10. typedef struct t_arg{
  11.     char *message;
  12.     int line;
  13. } thread_arg;
  14.  
  15. void *request_handler(void *t_arg);
  16. char *fifo = "/home/ubuntu/work/my_fifo";
  17.  
  18. int main(void){
  19.     mkfifo(fifo, 0666);
  20.     int srv_fifo = open(fifo, O_RDONLY);
  21.     char buff[1024];
  22.     while(1){
  23.         read(srv_fifo, buff, 1024);
  24.         pthread_t thread;
  25.         thread_arg arg;
  26.         arg.message = "Testing";
  27.         arg.line = 2001;
  28.         pthread_create(&thread, NULL, request_handler, &arg);
  29.         pthread_detach(thread);
  30.         memset(buff, 0, sizeof(buff));
  31.     }
  32. }
  33.  
  34. void *request_handler(void *t_arg){
  35.     thread_arg real_arg = *(thread_arg*)t_arg;
  36.     printf("%d",real_arg.line);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement