Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pthread.h"
- #include "stdio.h"
- #define N_THREADS 10
- #define N_RUNS 10000
- void* readStuff(void* a)
- {
- int i;
- for (i = 0; i< N_RUNS; i++){
- ;
- }
- pthread_exit((void*)0);
- }
- void* addRemove(void* a)
- {
- int i;
- for (i = 0; i< N_RUNS; i++){
- ;
- }
- pthread_exit((void*)0);
- }
- int main()
- {
- pthread_t threads[N_THREADS];
- pthread_attr_t attr;
- int i;
- int rc;
- int status;
- printf("Testing whether there are problems with concurrency ...");
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- for (i = 0; i < N_THREADS; i++){
- if (i) {
- rc = pthread_create(&(threads[i]), &attr, addRemove, 0);
- } else {
- rc = pthread_create(&(threads[i]), &attr, readStuff, 0);
- }
- if (rc) return rc;
- }
- for(i = 0; i < N_THREADS; i++) {
- rc = pthread_join(threads[i], (void*) &status);
- // if(rc == 3)
- printf("rc is %d. i is %d\n", rc, i);
- // if (rc) return rc;
- if (status) return status;
- printf(".");
- }
- pthread_attr_destroy(&attr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement