After switching from GLib2.40 to GLib2.42 g_mutex_trylock works incorrectly
Submitted by Sergei
Link to original bug (#739139)
Description
The previously well debugged code:
static gboolean check_schedules_new_and_replace_if_needed () {
gboolean res = FALSE;
if (g_mutex_trylock (&schedules_new.mutex)) {
LOG_INFO("TRYLOCKED OK!!! +++++++++++++");
if (g_strcmp0 (schedules.sql_ver, schedules_new.sql_ver) < 0) {
schedules_replace ();
g_timer_stop (schedules.filtering_timer);
g_timer_start (schedules.filtering_timer);
res = TRUE;
}
LOG_INFO("before UNLOCK +++++++++++++");
g_mutex_unlock (&schedules_new.mutex);
LOG_INFO("after UNLOCK +++++++++++++");
}
return res;
}
started to fail with the obvious error:
- the if above evaluates to
TRUE
, and the mutex is locked, -
"TRYLOCKED OK!!! +++++++++++++"
is printed -
"before UNLOCK +++++++++++++"
is printed - !!! then the messages
"Attempt to unlock mutex that was not locked"
and"Aborted (core dumped)"
are printed. - The message
"after UNLOCK +++++++++++++"
is never printed. - The mutex is initialized in the very beginning.
See the corresponding snipped of the real LOG:
2014-10-24 18:24:45.535 INFO (mp-main.c:278:check_schedules_new_and_replace_if_needed) TRYLOCKED OK!!! +++++++++++++
2014-10-24 18:24:45.535 INFO (mp-main.c:233:schedules_replace) schedule replacement for (null) -> db-as.00000183.sqlite3
2014-10-24 18:24:45.536 INFO (mp-main.c:285:check_schedules_new_and_replace_if_needed) before UNLOCK +++++++++++++
Attempt to unlock mutex that was not locked
Aborted (core dumped)
I just upgraded from Ubuntu 14.04 to 14.10, which also upgraded GLib from 2.40 to 2.42:
mp-2014-10-24_18:07:37.log.txt:2014-10-24 18:07:37.585 INFO (mp-main.c:430:main) GLib v2.40.0
mp-2014-10-24_18:07:47.log.txt:2014-10-24 18:07:47.655 INFO (mp-main.c:430:main) GLib v2.42.0
Version: 2.42.x
Edited by Emmanuele Bassi