Using THREAD_CREATE related macro definitions under Windows

Source: Internet
Author: User

#ifdef  _WIN32#include <windows.h>extern  "C"  {    extern int  getopt (int, char * const *, const char *);     Extern char *optarg;} #define  PATHD  ' \ \ ' typedef handle thread_t; #define  thread_create (thrp, attr, &NBSP;FUNC,&NBSP;ARG)                                       ((* (THRP)  = createthread (null, 0,                                                 (Lpthread_start_routine) (func),  (ARG),  0, null))  == null)  ? -1 : 0) #define     thread_join (THR,&NBSP;STATUSP)                                                   ((WaitForSingleObject (THR),  infinite  == wait_object_0)   &&                 ( Statusp == null)  ? 0 :                                   (GetExitCodeThread (THR),  (Lpdword) (STATUSP)) ( ? 0 : -1))) typedef handle mutex_t; #define &NBSP;MUTEX_INIT (m, attr)                                                         (((* (m)  = createmutex (null, false, null)  != null)   ?  0 : -1) #define  mutex_lock (m)                                                               ((WaitForSingleObject (* (m),  INFINITE)  == wait_object_0)  ? 0 : -1) #define  mutex_unlock (m)            (ReleaseMutex (* (m))  ? 0 : -1) #else #include  <pthread.h> #include  <unistd.h> #define  PATHD  '/' typedef pthread_t thread_t; #define  thread_ Create (Thrp, attr, func, arg)                                      pthread_create ((THRP),  (attr),  (func),  (ARG)) #define   Thread_join (THR,&NBSP;STATUSP)  pthread_join ((THR),  (STATUSP)) Typedef pthread_mutex_t mutex _t, #define &NBSP;MUTEX_INIT (m, attr)      pthread_mutex_init ((m),  (attr)) # Define mutex_lock (m)            pthread_mutex_lock ( m) #define  mutex_unlock (M)          pthread_mutex_unlock (M) # endif

Using thread_create-related macro definitions 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.