예제 #1
0
int main(int argc, char* argv[]) {

	if (argc < 2) {
		cout << "Not enough args ./sem <Num of threads>" << endl;
		return 1;
	}
	sscanf(argv[1], "%d", &threadNum);
    pthread_t tid[threadNum];
    sem_init(&sem, 0, 1);
    int returnCode;
    for (int i = 0; i < threadNum; ++i) {
        cout << "In main: Creating thread " << i << endl;
        returnCode = pthread_create(&tid[i], NULL, ThreadRunner, NULL);
        if (returnCode) {
            cout << "ERROR: Return Code from pthread_create is " << returnCode << endl;
            exit(-1);
        }
    }
    for (int i = 0; i < threadNum; ++i) {
        pthread_join(tid[i], NULL);
    } 
    sem_destroy(&sem);
    x.Print();
    pthread_exit(NULL);
    return 0;
}
예제 #2
0
파일: spinlock.cpp 프로젝트: allenwhale/OS
int main(){
    pthread_spin_init(&m_spinlock, 0);
    pthread_t tid[THREAD_NUM];
    for(int i=0;i<THREAD_NUM;i++)
        pthread_create(&tid[i], NULL, ThreadRunner, 0);
    for(int i=0;i<THREAD_NUM;i++)
        pthread_join(tid[i], NULL);
    x.Print();
    return 0;
}
예제 #3
0
int main(){
    pthread_t tid[thread_num];
    int i;
    for(i=0;i<thread_num;i++){
        pthread_create(&tid[i], NULL, ThreadRunner, 0);
    }
    for(i=0;i<thread_num;i++){
        pthread_join(tid[i], NULL);
    }
    x.Print();
    return 0;
}
예제 #4
0
int main(){
    pthread_t tid[3];
    int i;
    int t=100000000;
    for(i=0;i<3;i++){
        pthread_create(&tid[i], NULL, ThreadRunner, (void*) &t);
    }
    for(i=0;i<3;i++){
        pthread_join(tid[i], NULL);
    }
    x.Print();
    return 0;
}
예제 #5
0
int main() {
    time_t start_time = time(0);
    pthread_t tid[THDNUM];
    sem_init(&semaphore, 0, 1);
    int i;
    for (i = 0; i < THDNUM; i++)
        pthread_create(&tid[i], NULL, ThreadRunner, 0);
    for (i = 0; i < THDNUM; i++)
        pthread_join(tid[i], NULL);
    cout << "Result = ";
    x.Print();
    cout << "duration = " << time(0) - start_time << " secs" << endl;
    return 0;
}
예제 #6
0
int main() {
    srand (time(NULL));
    pthread_t tid[3];
    pthread_mutex_init (&p_mutex, NULL);
    for (int i = 0; i < 3;i++) {
        pthread_create(&tid[i], NULL, &ThreadRunner, 0);
    }

    for (int i =  0; i < 3; i++){
        pthread_join(tid[i], NULL);
    }
    pthread_mutex_destroy(&p_mutex);
    x.Print();
}