• 《POSIX多线程程序设计》笔记(2)作者自己写的两个调试宏函数源码


    开始看前面几个“闹钟”代码时,没找到errors.h到底在哪儿,原来。。。

    #include <pthread.h>
    #include <stdio.h>
    #include <errno.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
        pthread_t thread;
        int status;
    
        /*自死锁示例:
         *      大多数情况下,未初始化的pthread_t变量是一个无效线程ID,调用线程回收函数能正常检查出错误原因;
                但也有可能未初始化的值是一个有效的ID,此时,这个线程就进入了自死锁了.*/
        status = pthread_join(thread, NULL);
        if (status != 0)
        {
            /*strerror:
             *      区别于perror当关注当前errno对应的信息到标准错误,
             *      strerror是指定一个errno,并返回错误字符串,没有重定向到标准设备.*/
            fprintf(stderr, "error %d: %s
    ", status, strerror(status));                                                                  
            return status;
        }   
        return 0;
    } 
    #ifndef __errors_h                                                                                                                    
    #define __errors_h
    
    #include <unistd.h>
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #ifdef DEBUG
    #define DPRINTF(arg) printf arg
    #else
    #define DPRINTF(arg)
    #endif
    
    #define err_abort(code, text) do { 
        fprintf(stderr, "%s at "%s":%d: %s
    ", 
                text, __FILE__, __LINE__, strerror(code)); 
        abort(); 
        } while(0)
    #define errno_abort(text) do { 
        fprintf(stderr, "%s at "%s":%d: %s
    ", 
                text, __FILE__, __LINE__, strerror(errno)); 
        abort(); 
        } while(0)
    
    #endif
  • 相关阅读:
    Ubuntu 虚拟机安装几点细节整理
    jQuery与IE兼容性问题处理
    Excel已损坏,无法打开
    应对刷新闪烁问题
    ArcGIS鼠标滚轮方向之代码篇
    ChartControl控件0和null的效果
    多个组件联合打印输出——PrintableComponentLink
    Skyline中加载WMTS地图
    访问天地图WMTS服务的正确姿势
    超图不支持JPEG格式的WMTS服务
  • 原文地址:https://www.cnblogs.com/orejia/p/12555899.html
Copyright © 2020-2023  润新知