Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   No thread.h file? (http://www.programmingforums.org/showthread.php?t=13604)

Writlaus Jul 22nd, 2007 5:33 AM

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?

grumpy Jul 22nd, 2007 10:43 AM

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.

rwm Jul 23rd, 2007 3:55 AM

excellent tutorial on POSIX threads

http://www.llnl.gov/computing/tutorials/pthreads/

Random-Spirit Jul 23rd, 2007 7:41 AM

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.

Writlaus Jul 23rd, 2007 6:41 PM

pthreads sounds like what I want to use, but I don't have pthreads.h either... Can I get that somewhere?

DaWei Jul 23rd, 2007 7:59 PM

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.

Writlaus Jul 24th, 2007 1:28 AM

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.

Writlaus Jul 24th, 2007 1:51 AM

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.

ShawnStovall Aug 2nd, 2007 2:11 AM

Quote:

Originally Posted by Writlaus (Post 131048)
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.

It is a compressed file type(right?) and I found that I can get access to it by using a decompression program(I personally use 7-Zip). By decompressing it you get a .tar file and you can also use a decompression program to get into that also.

peace_of_mind Aug 2nd, 2007 12:23 PM

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