SHARE
TWEET

Untitled

a guest Jul 16th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4.  
  5.  
  6. #define N 50
  7.  
  8. struct message_group {
  9.     unsigned int level;
  10.     char* message[10];
  11.     struct message_group* others;
  12. };
  13.  
  14.  
  15. struct message_group* last;
  16. struct message_group* first;
  17. int y;
  18.  
  19.  
  20. void* thread_func(void* arg) {
  21.     int id = *((int*) arg);
  22.     printf("Tua mamma fa cose brutte ai cani.\n");
  23.  
  24.     if (id < 10*(last->level)) {
  25.         printf("Tua mamma dovrebbe avere la piattole.\n");
  26.         char* str = (char*) malloc(sizeof(char));
  27.         if (str == NULL) {
  28.             printf("No more space available in heap.\n");
  29.             exit(-1);
  30.         }
  31.         sprintf(str, "%d", id); // scrivo l'identificativo nel message
  32.         last->message[y] = str;
  33.         printf("Tua mamma potrebbe avere la piattole.\n");
  34.         y++;
  35.        
  36.     } else {
  37.             struct message_group* last;
  38.             last = (struct message_group*) malloc(sizeof(struct message_group));
  39.             if (last == NULL) {
  40.                 printf("No more space available in heap.\n");
  41.                 exit(-1);
  42.             }
  43.             printf("Tua mamma ha la sifilide.\n");
  44.             y = 0;
  45.             last->level = id+2;
  46.             last = last->others;
  47.  
  48.     }
  49.     printf("Tua mamma ha rotto il cazzo.\n");
  50.     pthread_exit(NULL);
  51. }
  52.  
  53.  
  54. void print(struct message_group* head) {
  55.    
  56.     int i;
  57.     while (head != NULL) {
  58.         for (i=0; i<10; i++) {
  59.             printf("%s ", head->message[i]);
  60.         }
  61.         head = head->others;
  62.         printf("\n");
  63.     }
  64. }
  65.    
  66.  
  67. int main(int argc, char* argv[]) {
  68.  
  69.     pthread_t tid;
  70.     void* status;
  71.  
  72.     last =  (struct message_group*) malloc(sizeof(struct message_group));
  73.     if (last == NULL) {
  74.         printf("No more space in heap available.\n");
  75.         exit(-1);
  76.     }
  77.     first = last;
  78.     last->level = 1;
  79.     y = 0;
  80.  
  81.     printf("Tu mamma รจ un lama.\n");
  82.  
  83.     for(int i=0; i<N; i++) {
  84.  
  85.         if (pthread_create(&tid, NULL, thread_func, (void*) &i)) {
  86.             printf("An error occurred while creating thread.\n");
  87.             exit(-1);
  88.         }
  89.  
  90.         if(pthread_join(tid, &status)) {
  91.             printf("An error occurred while joining the thread.\n");
  92.             exit(-1);
  93.         }
  94.  
  95.     }
  96.  
  97.     printf("Vorrei che tua mamma la facesse finita.\n");
  98.     printf("\n\n");
  99.     print(first);
  100.  
  101.     exit(0);
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top