Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #define NTHREAD 2
- pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
- char *mensagem;
- void* threadFunction(void* value){
- pthread_mutex_lock(&mtx);
- puts("thread: ");
- mensagem = (char) pthread_self();
- puts(mensagem);
- pthread_mutex_unlock(&mtx);
- }
- int main ()
- {
- pthread_t threads[NTHREAD];
- printf("Comecando o programa threads1 ... \n");
- int i;
- for(i=0; i<NTHREAD; i++){
- pthread_create(&threads[i], NULL, threadFunction, NULL);
- }
- for(i=0; i<NTHREAD; i++){
- pthread_join(threads[i], NULL);
- }
- printf("Terminando o programa threads1 ... \n");
- system("ps -f");
- exit (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment