Advertisement
Guest User

sdf

a guest
Sep 21st, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<pthread.h>
  4. #include<stdlib.h>
  5. #include<unistd.h>
  6.  
  7. pthread_t tid; // lol who cares about thread ids
  8.  
  9. typedef struct node {
  10. int data;
  11. struct node* left;
  12. struct node* right;
  13. } node;
  14.  
  15. void* thread_makenode(void* pnode){
  16. node n;
  17. n.left = NULL;
  18. n.right = NULL;
  19. *((node**) pnode) = &n;
  20. while(1);
  21. return NULL;
  22. }
  23.  
  24. node* makenode(int val){
  25. node* pnode = NULL;
  26. pthread_create(&tid, NULL, &thread_makenode, (void*) &pnode); // where is your god now
  27. while(!pnode);
  28. pnode->data = val;
  29. pnode->left = NULL;
  30. pnode->right = NULL;
  31. return pnode;
  32. }
  33.  
  34.  
  35. int main(void)
  36. {
  37. node* tree = makenode(1);
  38. tree->left = makenode(2);
  39. tree->right = makenode(3);
  40. printf("Root value: %d\n", tree->data);
  41. printf("Left value: %d\n", tree->left->data);
  42. printf("Right value: %d\n", tree->right->data);
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement