Exemple #1
0
void *yieldThread1() {
 int i=0;
        while(i<600) {
        mythread_mutex_lock(&lock);
//        mythread_mutex_lock(&lock1);

		if(glval==100) {
			mythread_cond_wait(&cond,&lock);
			sleep(1);
		}
		
                glval++;
                printOut(itoa(glval,10));
                printOut("\nthread1\n");
                glval1++;
//		mythread_enter_kernel();
//		mythread_unblock(&Q,1);
                printOut(itoa(glval1,10));
                printOut("\n");
        //mythread_mutex_unlock(&lock);
//        mythread_mutex_unlock(&lock1);
                i++;
        }
		
}
Exemple #2
0
void *thread5() {
        printOut("Thread5 Waiting on Condition Wait .Will be released by broadcast\n");
        mythread_mutex_lock(&lock1);

        mythread_cond_wait(&cond1,&lock1);  // in thread1/thread2 broadcast signal will be done
        printOut("Thread5 woken up by broadcast signal from Condition wait\n");
        mythread_mutex_unlock(&lock1);
}
Exemple #3
0
void *thread3() {

        printOut("Thread3 Waiting on Condition Wait\n");
	
	mythread_mutex_lock(&lock);
        mythread_cond_wait(&cond,&lock);

	printOut("Thread3 woken up from Condition wait\n");
	mythread_mutex_unlock(&lock);

}
Exemple #4
0
void *fun(void *arg)
{
	int i;

	mythread_mutex_lock(&mut);
	printf("Will now wait\n"); fflush(stdout);
	mythread_cond_wait(&cond, &mut);
	for(i = 0; i < INT_MAX/10; i++);
	printf("Exiting \n"); fflush(stdout);
	mythread_mutex_unlock(&mut);
	mythread_exit(NULL);
	return NULL;
}
void *runner(void *arg)
{
    int i;

    mythread_mutex_lock(&mutex);
    printf("Thread:Waiting for main thread to broadcast\n");
    fflush(stdout);
    mythread_cond_wait(&okToProceed, &mutex);
    sleep(0.2);
    printf("Thread:Out of conditonal wait and about to exit\n");
    fflush(stdout);
    mythread_mutex_unlock(&mutex);
    mythread_exit(NULL);
    return NULL;
}
// grab the lock. If count is less than 100, then wait for signal. Once signal is recieved, unlock mutex and wait on barrier. 
void *foo1 (void *arg)
{
    int test;
    mythread_mutex_lock (&mut);
    
    while (count < 100)             
    {
      mythread_cond_wait (&con, &mut);  
    }
        
   if ( mythread_mutex_unlock (&mut) != 0)
     PASS--;
        
   if ((test = mythread_barrier_wait (&barr) != 0) && (test != MYTHREAD_BARRIER_SERIAL_THREAD)) 
    PASS--;

    return NULL;
}
/* Each thread will increment the count (global) protected by mutex */
void* thread_func(void *arg)
{
	char buffer[1024];
	/*Lock Mutex*/
	int temp = 0;
	mythread_mutex_lock(&mutex);
	while(temp<1000){
		temp++;
	}
	/*Wait to increment until main thread signals*/
	mythread_cond_wait(&condition,&mutex);
	count++;
	mythread_enter_kernel();
	sprintf(buffer, "Incremented Count to : %d\n", count);
	printToConsole(buffer);
	mythread_leave_kernel();
	mythread_mutex_unlock(&mutex);
	/* Threads will wait on the barrier. Main thread will also wait */
	mythread_barrier_wait(&barrier);
	mythread_exit(NULL);	
}