function g_cond_timed_wait is not safe when change of datetime?
- From: "陈杰" <chenj lemote com>
- To: gtk-list gnome org
- Subject: function g_cond_timed_wait is not safe when change of datetime?
- Date: Fri, 21 Nov 2008 18:25:12 +0800
Hi, All
After calling g_get_current_time to get the current timeval, a call to *settimeofday* (maybe from another process), just before calling g_cond_timed_wait will cause some problem.
Say, the following code will cause the current process block for very long time:
GTimeVal tv, tv2;
g_get_current_time (&tv);
/* simulate a call from another process to change the current datetime to some *older* time */
tv2 = tv;
tv2.tv_sec -= 31536000;
tv.tv_sec += 10;
g_thread_init (NULL);
GCond *cond = g_cond_new ();
GMutex *mutex = g_mutex_new ();
/* need root privilege */
settimeofday ((struct timeval *) (&tv2), NULL);
g_mutex_lock (mutex);
g_print ("Before entering g_cond_timed_wait\n");
/* will block here for very long time */
g_cond_timed_wait (cond, mutex, &tv);
g_print ("End of g_cond_timed_wait\n");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]