![]() |
No thread.h file?
I was just about to start getting into threading, but when I try to, the compiler doesn't recognize things like THREADID and thread_create. So I figured I had to include a thread header file, but I don't have one that is related to threads. Should I have a thread.h file (or similar), or should my compiler be recognizing the thread things without it?
|
Neither.
Anything to do with threading (eg creating threads, executing functions in them, synchronisation between threads) is firmly outside the scope of standard C or C++. Both the C and C++ standards implicitly assume there is only one thread of execution in a program, which means there is no need for any support of multi-threading. There is some discussion in progress about changing that in a future version of those standards. thread_create() is a POSIX function (i.e. it is described in one of the POSIX [Portable Operating System Interface] family of standards). There is no requirement that a C or C++ compiler will recognise POSIX functions, no requirement that there will be a thread related header file, and no requirement that the library bundled with a compiler will include implementations of POSIX functions. If you want to use threads, you will need to read the documentation that comes with your compiler and its library. If you're lucky, they will support POSIX functions. If they don't support POSIX functions, they might support some other set of functions that can be used to implement threaded applications. If there is no threading support at all (which is the case for compilers targeting old systems, as threading typically relies on some form of support from an operating system) then you are probably out of luck. |
|
If you are on windows there are also the Win32 thread functions, CreateThread, TherminateThread etc. If you use Win32 threads it will not be easy to port your code to a non Win32 platform, so if portability is important or you are not using windows then POSIX threads are the way to go. On MSDN there is plenty of documentation on how to use Win32 threads properly. windows.h includes the prototypes for the Win32 thread functions.
|
pthreads sounds like what I want to use, but I don't have pthreads.h either... Can I get that somewhere?
|
Writ, you got tons of good responses. Did you bother to Google "pthreads"?? I did, so I'm going to have to guess, "No". Part of being a decent programmer is learning to change your own underwear.
|
Woah, hold on there. Yes, I did google pthreads, DaWei. Well, more specifically, I googled "pthreads download" (without the quotes). The links that looked promising didn't get me what I was looking for. I found one that I think would have worked, but it was a tar.gz, and to be honest I've never understood what I'm supposed to have to access those types of files. So, after a few dead-ends, I figured I'd just ask if someone knew of a link, since I already had the thread started--I wasn't trying to get people to look for me. I know I ask a lot of questions on here, but I always google first.
|
I found a link with the file available. Thanks a ton for the link to the tutorial, it looks like it will be great to start out with.
|
Quote:
|
He stated he found a link. There's no need to dredge up week old threads to offer a solution to a problem he's already solved.
|
| All times are GMT -5. The time now is 2:31 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC