1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "tpl.h"
4 #include <errno.h>
5 #include <string.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
8 #include <unistd.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <pthread.h>
12 
13 int fd[2];
14 
thread_routine(void * arg)15 void *thread_routine( void *arg ) {
16     tpl_node *tn;
17     int i,sum=0;
18 
19     /* child */
20     tn = tpl_map("A(u)",&i);
21     tpl_load(tn, TPL_FD, fd[0]);
22     while (tpl_unpack(tn,1) > 0) sum += i;
23     tpl_free(tn);
24     printf("sum is %d\n", sum);
25     return NULL;
26 }
27 
main()28 int main() {
29     tpl_node *tn;
30     unsigned i;
31     int status;
32     pthread_t thread_id;
33     void *thread_result;
34 
35     pipe(fd);
36     if ( status = pthread_create( &thread_id, NULL, thread_routine, NULL )) {
37         printf("failure: status %d\n", status);
38         exit(-1);
39     }
40     /* parent */
41     tn = tpl_map("A(u)",&i);
42     for(i=0;i<10000;i++) tpl_pack(tn,1);
43     tpl_dump(tn,TPL_FD, fd[1] );
44     tpl_free(tn);
45 
46     status = pthread_join( thread_id, &thread_result );
47     printf("thread result: %d %s\n", status, thread_result ? "non-null":"null");
48 }
49