Static compilation pthread under Windows

Source: Internet
Author: User

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

General:ptw32_static_lib must is defined for both the library build and the
Application build. The makefiles supplied and used by the following ' make '
Command lines would 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 and non-portable routines to initialise the
Some state on startup and cleanup before exit. One other routine needs
To is called to cleanup after any Win32 threads has 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 has the same targets but only check the
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. Using the Pthread-win32 Static library
Use Pthread-win32 Static library to note:
1) in the program to define the macro Ptw32_static_lib
2) Pthread-win32 Static library does not do attach and detach operations, to the programmer to complete the task,
Otherwise the line threads can be created successfully. Specific as follows:
The following two functions are called at the entrance of the program (usually the main function)
PTHREAD_WIN32_PROCESS_ATTACH_NP ();
PTHREAD_WIN32_THREAD_ATTACH_NP ();
Called at the end of the program
PTHREAD_WIN32_THREAD_DETACH_NP ();
PTHREAD_WIN32_PROCESS_DETACH_NP ();

No way, the Windows system has a lot of standards it does not support, it is necessary to write a little trouble.
This can be done simply by:

A) define the processing function at the end of the program
#ifdef Ptw32_static_lib
void Pthread_win32_detach (void)
{
PTHREAD_WIN32_THREAD_DETACH_NP ();
PTHREAD_WIN32_PROCESS_DETACH_NP ();
}
#endif

b) call at the entrance of the program as follows
#ifdef Ptw32_static_lib
PTHREAD_WIN32_PROCESS_ATTACH_NP ();
PTHREAD_WIN32_THREAD_ATTACH_NP ();
Atexit (Pthread_win32_detach);
#endif

Static compilation pthread under Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.