• windows下静态编译pthread


    1. Building the library as a statically linkable library
    -----------------------------------------------------

    General: PTW32_STATIC_LIB must be defined for both the library build and the
    application build. The makefiles supplied and used by the following 'make'
    command lines will define this for you.

    MSVC (creates pthreadVCn.lib as a static link lib):

    nmake clean VC-static


    MinGW32 (creates libpthreadGCn.a as a static link lib):

    make clean GC-static


    Define PTW32_STATIC_LIB when building your application. Also, your
    application must call a two non-portable routines to initialise the
    some state on startup and cleanup before exit. One other routine needs
    to be called to cleanup after any Win32 threads have called POSIX API
    routines. See README.NONPORTABLE or the html reference manual pages for
    details on these routines:

    BOOL pthread_win32_process_attach_np (void);
    BOOL pthread_win32_process_detach_np (void);
    BOOL pthread_win32_thread_attach_np (void); // Currently a no-op
    BOOL pthread_win32_thread_detach_np (void);


    The tests makefiles have the same targets but only check that the
    static library is statically linkable. They don't run the full
    testsuite. To run the full testsuite, build the dlls and run the
    dll test targets.

    =============================================

    2. 使用pthread-win32静态库
    使用pthread-win32静态库要注意:
    1) 在程序中要定义宏PTW32_STATIC_LIB
    2) pthread-win32静态库中没有做attach和detach操作,要程序员来完成该任务,
    否则线程有能成功创建。具体如下:
    在程序入口(通常是main函数)处调用如下两个函数
    pthread_win32_process_attach_np();
    pthread_win32_thread_attach_np();
    程序结束时调用
    pthread_win32_thread_detach_np();
    pthread_win32_process_detach_np();

    没办法,windows系统有很多标准它都不支持,写起来就要麻烦点。
    可以简单地这样处理:

    a) 定义程序结束时的处理函数
    #ifdef PTW32_STATIC_LIB
    void pthread_win32_detach(void)
    {
    pthread_win32_thread_detach_np();
    pthread_win32_process_detach_np();
    }
    #endif

    b) 在程序入口处调用如下
    #ifdef PTW32_STATIC_LIB
    pthread_win32_process_attach_np();
    pthread_win32_thread_attach_np();
    atexit(pthread_win32_detach);
    #endif

  • 相关阅读:
    (转)C#特性详解
    PHP MSSQL数据操作PDO API
    DWR
    配置JAVA的环境变量
    关​于​h​i​b​e​r​n​a​t​e​中​双​向​外​键​关​联​o​n​e​-​t​o​-​o​n​e​的​p​r​o​p​e​r​t​y​-​r​e​f​=​的​问​题(转)
    Hibernate 二级缓存 总结整理(转)
    EhCache 分布式缓存/缓存集群(转)
    MySQL分区表(转)
    通用权限设计
    (转)关于Struts 2 拦截器参数丢失问题
  • 原文地址:https://www.cnblogs.com/guoxiaoqian/p/4380637.html
Copyright © 2020-2023  润新知