c11threads icon indicating copy to clipboard operation
c11threads copied to clipboard

Windows threads support

Open jimon opened this issue 8 years ago • 5 comments

Would be really nice to see win threads support here! I might do it because I'm quite desperate looking for C-only cross-platform threading lib.

jimon avatar Jun 26 '16 18:06 jimon

I might be missing something, but what would networking have to do with a C11 threads implementation?

jtsiomb avatar Jun 26 '16 23:06 jtsiomb

There are very few threads.h implementations atm, and looks like no implementation for Windows. threads.h meant to be platform-independent header, so would be nice to add win support in one place, otherwise community will end-up with two different headers :(

jimon avatar Jun 27 '16 08:06 jimon

Probably most of stuff could be copy-pasted from here https://github.com/tinycthread/tinycthread with saving license note.

jimon avatar Jun 27 '16 08:06 jimon

So you meant "windows threads", not "windows sockets". Then sure, it would be nice to have C11 threads on windows.

But I don't think this is the place to do that. I have implemented pthreads on windows in the past, and the problem is the win32 API doesn't have a condvar-equivalent construct. This means that a full implementation of C11 threads can't really be a header-only thin wrapper, but rather a full library, like the one you linked. So I suggest using that one instead if you care about windows compatibility.

Still, having said that, if someone cares to contribute a win32 implementation to this "project", and it's clean and well written enough, I will include it.

jtsiomb avatar Jun 27 '16 15:06 jtsiomb

Ah yes, threads! it was too late in the evening :)

jimon avatar Jun 27 '16 15:06 jimon

the win32 API doesn't have a condvar-equivalent construct

Mesa has a header-only implementation [1] and it uses the Win32 functions for condition variables.

[1] https://gitlab.freedesktop.org/mesa/mesa/-/blob/22.1/include/c11/threads_win32.h

oold avatar Dec 21 '22 22:12 oold

Nice, I guess they added condition variables to win32 at some point. It was later than the last time I had to deal with win32 programming though. It's only available on windows vista and later.

Nevertheless, that sounds like a good candidate for a windows port of c11threads. So as I said previously, if anyone cares to contribute a windows implementation of all this, I'll be glad to review any pull requests or patches.

jtsiomb avatar Dec 21 '22 23:12 jtsiomb

Pull request #21 adding support for win32 has been merged.

jtsiomb avatar Jan 04 '23 21:01 jtsiomb