Strange problem with gettimeoftheday function

Hi all,
I am using pthread_cond_timedwait function in my program, to generate the time period of waiting i use gettimeoftheday function.

When i run the code after compiling i get a core dump error. However my program runs perfectly if i give a printf statement before the gettimeoftheday function. :confused: Can anyone explain this problem . I have pasted the part of the code for your reference:

            pthread\_mutex_lock\(&lock\);
	//printf\("After core dump \\n"\);		
	gettimeofday\(&tp, NULL\);
	ts.tv_sec  = tp.tv_sec;
    	ts.tv_nsec = tp.tv_usec * 1000;
    	ts.tv_sec \+= WAIT\_TIME_SECONDS;		
	pthread\_cond_timedwait\(&write, &lock, &ts\);
	pthread\_mutex_unlock\(&lock\);

Thanks in advance,

Sorry I mentioned the function name wrongly. It is gettimeofday and not gettimeoftheday.