Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // multiplas tarefas (thread)
- // Apple Xcode
- // paulogp
- #include <stdio.h>
- #include <time.h>
- #include <pthread.h>
- struct char_print_parms
- {
- char character;
- int count;
- };
- void* char_print (void* parameters)
- {
- int i;
- struct char_print_parms* p = (struct char_print_parms*) parameters;
- for (i = 0; i < p->count; i++)
- {
- fputc(p->character, stderr);
- }
- return NULL;
- }
- int main (int argc, const char * argv[])
- {
- pthread_t the_thread_id_1, the_thread_id_2;
- struct char_print_parms t1_args;
- struct char_print_parms t2_args;
- t1_args.character = 'x';
- t1_args.count = 30000;
- pthread_create(&the_thread_id_1, NULL, char_print, &t1_args);
- t2_args.character = 'o';
- t2_args.count = 20000;
- pthread_create(&the_thread_id_2, NULL, char_print, &t2_args);
- // nao queremos que o processo termine antes de ambas
- // as threads terminarem
- pthread_join(the_thread_id_1, NULL);
- pthread_join(the_thread_id_2, NULL);
- printf("\ndone\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement