Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #define MAX 10000
- struct TContext {
- const char* text;
- };
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- void* ThreadFunc(void* arg) {
- struct TContext* ctxt = arg;
- for (int i = 0; i < MAX; ++i) {
- printf("%s", ctxt->text);
- }
- pthread_exit(0);
- }
- int main() {
- pthread_mutex_init(&mutex, NULL);
- pthread_cond_init(&cond, NULL);
- pthread_t t1;
- pthread_t t2;
- pthread_t t3;
- int counter = 0;
- struct TContext ctxt1 = {"a"};
- struct TContext ctxt2 = {"b"};
- struct TContext ctxt3 = {"c"};
- pthread_create(&t1, 0, ThreadFunc, &ctxt1);
- pthread_create(&t2, 0, ThreadFunc, &ctxt2);
- pthread_create(&t3, 0, ThreadFunc, &ctxt3);
- pthread_join(t1, 0);
- pthread_join(t2, 0);
- pthread_join(t3, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement