- #include <gio/gio.h>
- #include <stdlib.h>
- #include <string.h>
-
- gpointer pop_data_timed(void) {
- gboolean current_data = 0;
- gint64 end_time;
- gpointer data;
-
- GCond data_cond;
- GMutex data_mutex;
-
- g_print("start timer: %ld\n", g_get_monotonic_time());
- g_mutex_lock(&data_mutex);
-
- end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
- g_print("wait until: %ld\n", end_time);
-
- while (!current_data) {
- g_print("while\n");
- if (!g_cond_wait_until(&data_cond, &data_mutex, end_time)) {
- g_print("timeout: %ld\n", g_get_monotonic_time());
- g_mutex_unlock(&data_mutex);
- return NULL;
- }
- }
-
- g_mutex_unlock(&data_mutex);
-
- return data;
- }
-
-
- int main(int argc, char **argv) {
- GApplication *app;
- int status;
-
- app = g_application_new("org.gtk.TestApplication", G_APPLICATION_HANDLES_COMMAND_LINE);
- g_signal_connect(app, "command-line", G_CALLBACK(pop_data_timed), NULL);
- g_application_set_inactivity_timeout(app, 10000);
-
- status = g_application_run(app, argc, argv);
-
- g_object_unref(app);
-
- return status;
- }