Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #define N 50
- struct message_group {
- unsigned int level;
- char* message[10];
- struct message_group* others;
- };
- struct message_group* last;
- struct message_group* first;
- int y;
- void* thread_func(void* arg) {
- int id = *((int*) arg);
- printf("Tua mamma fa cose brutte ai cani.\n");
- if (id < 10*(last->level)) {
- printf("Tua mamma dovrebbe avere la piattole.\n");
- char* str = (char*) malloc(sizeof(char));
- if (str == NULL) {
- printf("No more space available in heap.\n");
- exit(-1);
- }
- sprintf(str, "%d", id); // scrivo l'identificativo nel message
- last->message[y] = str;
- printf("Tua mamma potrebbe avere la piattole.\n");
- y++;
- } else {
- struct message_group* last;
- last = (struct message_group*) malloc(sizeof(struct message_group));
- if (last == NULL) {
- printf("No more space available in heap.\n");
- exit(-1);
- }
- printf("Tua mamma ha la sifilide.\n");
- y = 0;
- last->level = id+2;
- last = last->others;
- }
- printf("Tua mamma ha rotto il cazzo.\n");
- pthread_exit(NULL);
- }
- void print(struct message_group* head) {
- int i;
- while (head != NULL) {
- for (i=0; i<10; i++) {
- printf("%s ", head->message[i]);
- }
- head = head->others;
- printf("\n");
- }
- }
- int main(int argc, char* argv[]) {
- pthread_t tid;
- void* status;
- last = (struct message_group*) malloc(sizeof(struct message_group));
- if (last == NULL) {
- printf("No more space in heap available.\n");
- exit(-1);
- }
- first = last;
- last->level = 1;
- y = 0;
- printf("Tu mamma รจ un lama.\n");
- for(int i=0; i<N; i++) {
- if (pthread_create(&tid, NULL, thread_func, (void*) &i)) {
- printf("An error occurred while creating thread.\n");
- exit(-1);
- }
- if(pthread_join(tid, &status)) {
- printf("An error occurred while joining the thread.\n");
- exit(-1);
- }
- }
- printf("Vorrei che tua mamma la facesse finita.\n");
- printf("\n\n");
- print(first);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement