Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<pthread.h>
- #include<stdlib.h>
- #include<unistd.h>
- pthread_t tid; // lol who cares about thread ids
- typedef struct node {
- int data;
- struct node* left;
- struct node* right;
- } node;
- void* thread_makenode(void* pnode){
- node n;
- n.left = NULL;
- n.right = NULL;
- *((node**) pnode) = &n;
- while(1);
- return NULL;
- }
- node* makenode(int val){
- node* pnode = NULL;
- pthread_create(&tid, NULL, &thread_makenode, (void*) &pnode); // where is your god now
- while(!pnode);
- pnode->data = val;
- pnode->left = NULL;
- pnode->right = NULL;
- return pnode;
- }
- int main(void)
- {
- node* tree = makenode(1);
- tree->left = makenode(2);
- tree->right = makenode(3);
- printf("Root value: %d\n", tree->data);
- printf("Left value: %d\n", tree->left->data);
- printf("Right value: %d\n", tree->right->data);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement