Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/sem.h>
- #include <sys/ipc.h>
- #include <sys/types.h>
- #include <sys/syscall.h>
- #include <pthread.h>
- #include <fcntl.h>
- #include <string.h>
- #include <errno.h>
- void* funzione(void* args)
- {
- //filename=(FILE*)args;
- printf("SONO IL THREAD CON TID: %d\n", pthread_self());
- char* frase="roma2";
- FILE* f = fopen("sincro.txt", "w+"); if (f == NULL) {printf("errno val: %d\n", errno); exit (-1);}
- printf("check\n");
- fprintf(f, "%s", frase);
- //fwrite(frase, 1, dim, filename);
- //fflush(stdin);
- fclose(f);
- //printf("%s\n", frase);
- exit(0);
- }
- void* funzione_b(void* args)
- {
- char* frase_b="pongo";
- FILE* f = fopen("sincro.txt", "a"); if (f == NULL) {printf("errno val: %d\n", errno); exit (-1);}
- printf("check\n");
- for (int i=0; i<10; i++)
- {
- fprintf(f, "%s", frase_b);
- }
- //fflush(sfile);
- fclose(f);
- //printf("%s\n", frase_b);
- exit(0);
- }
- int main()
- {
- void* res;
- pthread_t ta;
- pthread_t tb;
- pthread_create(&ta, NULL, funzione, NULL);
- pthread_create(&tb, NULL, funzione_b, NULL);
- pthread_join(ta, &res);
- pthread_join(tb, &res);
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement