Hello everyone,

It is with great honor that I bring you the C11-conforming header for thread 
support of mcfgthread, c11thread.h:
https://github.com/lhmouse/mcfgthread/blob/master/src/env/c11thread.h
All headers in the mcfgthread project have been put into the public domain.

As JonY suggested a few days ago, it would be nice for mingw-w64 to have C11 
thread support.
This announcement is not only a call for testers, but also a proposal for a C11 
header for mingw-w64. We can have both C11 and C++11 threads from today.

The following code illustrates how to use C11 threads:
```
E:\Desktop>expand -t4 test.c
#include <mcfgthread/c11thread.h>
#include <stdio.h>
#include <stdlib.h>

int thread_proc(void *param){
    printf("thread running: tid = %u, param = %p\n", (unsigned)thrd_current(), 
param);
    for(int i = 0; i < 5; ++i){
        printf("thread going to sleep for one second...\n");
        struct timespec ts;
        ts.tv_sec = 1;
        ts.tv_nsec = 0;
        thrd_sleep(&ts, 0);
    }
    int exit_code = 67890;
    printf("thread exiting: exit_code = %d\n", exit_code);
    return exit_code;
}

int main(){
    thrd_t tid;
    int err;
    if((err = thrd_create(&tid, &thread_proc, (void *)0x12345)) != 
thrd_success){
        printf("thrd_create() returned %d\n", err);
        abort();
    }
    printf("created thread: tid = %u\n", (unsigned)tid);
    int exit_code;
    if((err = thrd_join(tid, &exit_code)) != thrd_success){
        printf("thrd_join() returned %d\n", err);
        abort();
    }
    printf("joined thread: exit_code = %d\n", exit_code);
}

E:\Desktop>gcc test.c -std=c11 -Wall -Wextra -pedantic -lmcfgthread

E:\Desktop>a.exe
created thread: tid = 9876
thread running: tid = 9876, param = 00012345
thread going to sleep for one second...
thread going to sleep for one second...
thread going to sleep for one second...
thread going to sleep for one second...
thread going to sleep for one second...
thread exiting: exit_code = 67890
joined thread: exit_code = 67890

E:\Desktop>
```

In order to use C++11 std::thread (as well as std::mutex, 
std::condition_variable, etc) you must rebuild GCC and its libraries.
A few instructions can be found here: https://github.com/lhmouse/mcfgthread/wiki

                                
--------------
Best regards,
lh_mouse
2016-06-19


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://sdm.link/zohomanageengine
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to