glib GMainLoop GMainContext GSource

//mainloop0.c   #include    GMainLoop* loop;    int main(int argc, char* argv[])    {        //g_thread_init是必需的,GMainLoop需要gthread库的支持。       if(g_thread_supported() == 0)           g_threa
摘要由CSDN通过智能技术生成

  1. //mainloop0.c   
  2. #include<glib.h>    
  3. GMainLoop* loop;   
  4. int main(int argc, char* argv[])   
  5. {   
  6.     //g_thread_init是必需的,GMainLoop需要gthread库的支持。   
  7.     if(g_thread_supported() == 0)   
  8.         g_thread_init(NULL);   
  9.     //创建一个循环体,先不管参数的意思。   
  10.     g_print("g_main_loop_new\n");   
  11.     loop = g_main_loop_new(NULL, FALSE);   
  12.     //让这个循环体跑起来   
  13.     g_print("g_main_loop_run\n");   
  14.     g_main_loop_run(loop);   
  15.     //循环运行完成后,计数器减一   
  16.     //glib的很多结构类型和c++的智能指针相似,拥有一个计数器   
  17.     //当计数器为0时,自动释放资源。   
  18.     g_print("g_main_loop_unref\n");   
  19.     g_main_loop_unref(loop);   
  20.     return 0;   
  21. }  

 

好了,现在编译:

  1. gcc -g `pkg-config --cflags --libs glib-2.0 gthread-2.0` mainloop0.c -o mainloop0  

然后运行:

./mainloop0

你会发现程序会在g_main_lo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值