glibc中定时器的使用

示例代码:

/*
 * =====================================================================================
 *
 *       Filename:  main.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2017年07月18日 16时05分27秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  yingc (), admin@srcbin.net
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

gboolean calbackfu(gpointer nouse )
{
    printf("callback\n");
    return TRUE;
}

int main ()
{
    GMainLoop *loop;

    loop = g_main_loop_new (NULL, TRUE);
    g_timeout_add(1000, calbackfu, NULL);

    g_main_loop_run(loop);

    return 0;
}

 

编译:

gcc -g -O0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include main.c -lglib-2.0

  

posted @ 2017-07-18 16:51  源码盒子(srcbin.net)  阅读(590)  评论(0编辑  收藏  举报