This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug linuxthreads/261] pthread_cond_timedwait_relative hangs


------- Additional Comments From jiten dot a at gmail dot com  2004-07-11 10:00 -------
(From update of attachment 131)
>#include <pthread.h>
>#include <iostream>
>#include <unistd.h>
>#include <stdlib.h>
>#include <string.h>
>#include <errno.h>
>#include <sys/time.h>
>
>#define NUM_LOADERS 240
>#define TIMEOUT_MILLISEC 20
>
>
>using namespace std;
>
>bool resource_avl= true;
>
>//pthread_mutex_t mu	=	PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
>pthread_mutex_t mu	=	PTHREAD_MUTEX_INITIALIZER;
>pthread_cond_t  co	=	PTHREAD_COND_INITIALIZER;
>
>
>
>void *loader(void*)
>{
>	pthread_detach(pthread_self());
>				
>	struct timeval tv;
>	struct timespec ts;
>	struct timespec tts;
>
>	int ret=0;
>	
>	while(1)
>	{
>		pthread_mutex_lock(&mu);
>
>		while(!resource_avl)
>		{
>				gettimeofday(&tv,NULL);
>				ts.tv_sec = tv.tv_sec;
>				ts.tv_nsec = (tv.tv_usec + TIMEOUT_MILLISEC*1000)*1000;
>				ret = pthread_cond_timedwait(&co,&mu,&ts);
>				if(ret == ETIMEDOUT)
>				{
>					cout << "Timed out:" << pthread_self() << endl;
>				}
>		}
>
>		cout << "TAKEN: "<< pthread_self() <<endl;
>		cout.flush();
>		resource_avl=false;
>		pthread_mutex_unlock(&mu);
>		
>		cout << "WORKING: "<< pthread_self() <<endl;
>
>		tts.tv_sec = 0;
>		tts.tv_nsec = 10*1000000;
>		nanosleep(&tts,NULL);	
>
>
>		pthread_mutex_lock(&mu);
>
>		cout << "RELEASED: "<< pthread_self() <<endl;
>
>		resource_avl=true;
>
>		pthread_cond_signal(&co);
>		pthread_mutex_unlock(&mu);
>		
>		tts.tv_sec = 0;
>		tts.tv_nsec = 70*1000000;
>		nanosleep(&tts,NULL);	
>	
>	}
>
>				
>}
>
>
>#define SIZE 1024*1024
>
>void *doPaging(void *f)
>{
>    char *x;
>    int counter=0;
>    
>    while(1) {
>         counter++;   
>         if(counter%20 == 0) counter=1;
>
>         x = new char[SIZE * counter%20 ];
>         cout << "Done new" << endl;cout.flush();
>      
>         usleep(10000);
>         delete []x;
>    }    
>}
>/*
>void *doPaging(void *f)
>{
>    char *x, *p;
>    x = (char*)malloc(SIZE*sizeof(char));
>
>    if(!x)
>    {
>      cout << "Couldnt allocate memory for test" << endl;
>      exit (1);      
>    }
>    
>    while(1) {
>         memset(x,0 ,SIZE*sizeof(char));
>         cout << "Done memset" << endl;cout.flush();
>      usleep(10000);
>    }    
>}
>*/
>
>
>int main()
>{
>	pthread_t load_tid[NUM_LOADERS];
>	int ret=0;
>		
>	for(int i=0; i < NUM_LOADERS; i++)
>	{
>		ret = pthread_create(&load_tid[i], NULL, loader, NULL);
>		if(ret != 0)
>		{
>			cout << "Error Creating thread" << endl;			
>		}
>		else
>		{
>			cout << "Thread created successfully" <<endl;			
>		}
>	}
>	
>  pthread_t pagerid;
>	ret = pthread_create(&pagerid, NULL, doPaging, NULL);
>  if(ret != 0)
>	{
>		cout << "Error Creating Pager thread" << endl;			
>	}
>	else
>	{
>		cout << "Pager Thread created successfully" <<endl;			
>	}
>
>	while(1)
>		sleep(100000);
>				
>}


-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=261

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]