zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    AWK只打印某个域后的所有域
    Apache配置文件httpd.conf内容翻译
    DOM事件类型详解
    DOM中的事件处理概览与原理的全面剖析
    JavaScript实战(带收放动画效果的导航菜单)
    (转)高性能JavaScript:加载和运行(动态加载JS代码)
    (转)网页性能管理详解
    (转)JavaScript-性能优化之函数节流(throttle)与函数去抖(debounce)
    你真的知道setTimeout是如何运行的吗
    用原生JS读写CSS样式的方法总结
  • 原文地址:https://www.cnblogs.com/guoxiaoqian/p/4380637.html
Copyright © 2011-2022 走看看