Subj : Re: Help me using pthreah!!! :) please... To : comp.programming.threads From : ptjm Date : Sat Jun 25 2005 02:42 pm In article <6cbve.1351$h5.55369@news3.tin.it>, tranky wrote: % I've this code of Reader-Writer Problem. I want that writer 2 starts N % seconds % after the execution of writer1. % What i will do?? % I thing i will use the function pthread_kill e sigwait, but i don't know how % to! Don't use pthread_kill() for this. Use a condition variable to signal state changes between threads. Writer 2 would do something like this pthread_mutex_lock(&mux); while (waiting_for_writer_one) pthread_cond_wait(&mux, &cv); waiting_for_writer_one = 0; pthread_mutex_unlock(&mux); sleep(N); /* for whatever reason */ Writer 1 would do this at the point it wants writer 2 to start sleeping: pthread_mutex_lock(&mux); waiting_for_writer_one = 1; pthread_mutex_unlock(&mux); pthread_cond_signal(&cv); % (and if is possible can you say me how create a sixth thread that starts % ever N second after the starting of the program?!?) It could just sleep for N seconds. If the drift you get (after sleeping for N seconds 10 times, N*10 + D seconds will have passed for some D > 0), you could use clock_nanosleep struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts): while (1) { ts.tv_sec += N; while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts) == EINTR) ; do_whatever(); } -- Patrick TJ McPhee North York Canada ptjm@interlog.com .