chrisname... all of those answers could be answered by reading the documentation.
You should never use any API function without reading the documentation. Especially where threads are concerned. POSIX is no exception.
But anyway.. .without having checked the documentation... and having actually used CreateThread like maybe 3 times before in my life (many many many years ago), I can tell you the following:
- What the hell is a HANDLE WINAPI? |
WINAPI is a calling convention. Granted there's no way to know this from that snippit you posted unless you are semifamiliar with WinAPI.
A HANDLE is just that: a handle. Essentially it is the object that represents the thread.
Handles aren't really that weird of a concept -- they're all over WinAPI. Maybe you're just not that familiar with them?
- lpThreadAttributes: What's this? Is it a bitmap? A struct?
|
The 'LP' suggests is a pointer to a struct named 'SECURITY_ATTRIBUTES'. Probably to specify things like thread priority and whatnot. Of course if you want to use it you'll have to check the documentation for SECURITY_ATTRIBUTES. If you don't want to use it, you can pass NULL as the bit you posted indicates the parameter is optional.
- dwStackSize: Ok, fair enough. I don't see why I need to specify this, but whatever |
Admittedly, that one does seem strange to me as well. But the documentation probably recommends a default value to use.
- lpParameter: parameter for what? |
For your callback. Seemed pretty obvious to me. Callbacks are pretty much always bundled with a void pointer for user data. Even the POSIX function you posted has this.
- dwCreationFlags: no idea what to do with this |
Same. But if you skimmed the documentation, I'm sure you'd know.
- lpThreadId: don't have a clue what this is meant to be |
Well it's an 'out' parameter, and it's named 'lpThreadId', so I'm guessing it gives you the thread ID. But it's optional, too, so you can just give it NULL.
Return value:
- A C/C++ programmer who doesn't know what an int is should be shot
Arguments: |
What is the int, though? Like what does it represent? Is it a faux boolean value that tells you whether or not the thread succeeded? Like an error code? Or is it some kind of ID to the thread?
(Yes I know I could check the documentation to see what it actually is. I'm just trying to point out that it's not as simple as you're trying to make it look)
How are you meant to figure out what an LPSECURITY_ATTRIBUTES is? Naturally you'd open windows.h and look for "#define LPSECURITY_ATTRIBUTES" but it might be a typedef. |
"Naturally"? Wtf? That's completley unnatural. Who does that?
You don't sift through header files looking for stuff, you read the documentation. That's why documentation exists.
google, msdn, etc.
- attr: again, you probably don't know what a pthread_attr_t is, but at least you know it's almost certainly a typedef. Besides, the man page will inform you that it can be NULL. |
How is this
any different from SECURITY_ATTRIBUTES?
To me, the POSIX API is much, much better than the windows one. I can actually read code that uses it! |
Those two functions are practically the same. The WinAPI version only has 2 extra parameters, one of which is clearly marked as optional.
Actually maybe I counted wrong (actually I didn't count). Is there 3? Maybe that is a little excessive. Still I don't think it's too horrible.