![]() |
|
#1
|
|||
|
|||
pthread trick works with gcc 3.x.x, but not with 4.x.xAt may 2000 issue of the drJobbs journal was a cool trick to do posix threading with cpp.
Here is the original paper: HTML Code:
Recently I tried to use it again, but it does not compile any more. After few tries I found out that it still builds with gcc 3.x.x. Apparently gcc 4.x.x. is more strict. What is the problem and how to solve it?? Comple attached example by: g++ -lpthread main.cpp (@ pdf document above are the original examples) CPP / C++ / C Code:
|
|||
|
#2
|
||||
|
||||
Re: pthread trick works with gcc 3.x.x, but not with 4.x.xI don't have the environment available right now. Could you please post the error message(s)?
Thanks, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
Re: pthread trick works with gcc 3.x.x, but not with 4.x.xoops.
$ g++ -lpthread main1.cpp main1.cpp: In member function ‘void Thread::Create()’: main1.cpp:12: error: ‘thread_func’ was not declared in this scope $ -antti |
|
#4
|
||||
|
||||
Re: pthread trick works with gcc 3.x.x, but not with 4.x.xYou probably just need to let the compiler know of the signature of the function before implementing the method in the class.
Try to either declare the prototype of thread_func prior to the Class definition, or to simply move the entire function implementation before the class. A code similar to the one you posted compiles fine in Visual Studio, and I don't have the Standard handy, nor the time to search in the Behemoth. __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#5
|
|||
|
|||
Re: pthread trick works with gcc 3.x.x, but not with 4.x.xQuote:
Quote:
With g++ version 4.1.2 on my Centos 5.1 Linux platform, the following works: CPP / C++ / C Code:
Output: Code:
Regards, Dave |
|
#6
|
|||
|
|||
Re: pthread trick works with gcc 3.x.x, but not with 4.x.xGreat, thanks to all.
That was a a really trivial error that I made. -a |
|
#7
|
||||
|
||||
Re: pthread trick works with gcc 3.x.x, but not with 4.x.xQuote:
You are right. I wrote the suggestion without actually trying it out - sorry. __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The