|
From: Alessandro A. <ant...@gm...> - 2011-12-23 11:25:07
|
Hi, Paul. > Relation in use... do you mean they are equivilant, but each for their > respective platform? Or are you saying that although they do > the same sort of thing, they actually are *not* the same? If the > operations by the compiler are different, is that difference only in > what is necessary to accomodate the respective OS targets, or different > in some other way? Well, they are equivalent but they don't do the same thing. Using '-pthread' GCC adds support for using pthreads library, setting flags both in the preprocessor and in the linker stage. pthreads library is a default multithreaded development in Linux, but not in Windows. On Windows you can develop a multithreaded application without pthreads. Using the Windows SDK. But you do need to use -mthreads so the compiler can add thread-safe exception handling and compile to the right Windows runtime library. I don't know about libpthreadGC2.a. By your link seams a different library. > So it seems that -mthreads and -pthread correspond, but are not > equivilant. In my case I know that the application hasn't been ported > to windows, as that's what I'm trying to do. What I need to know is what > it would take to port it. Just using -mthreads has so far produced a > seemingly working binary, so the code can't be using anything too linux > specific, but is there a good chance that using -mthreads has made the > code unsound somehow, and if so what would I need to look out for in > the code that would need to be re-written, or what compiler options > could I use to ensure the binary I get is sound? I haven't done a port like that but I have successful created an application using pthreads-w32. Although on Linux you can use -pthread to import and link against libpthread.a, on Windows you will use -mthreads only to set the right runtime library. You will need to import libpthread.a by your self. And look in the documentation to see what differences you need to know about the implementation in the two platforms. > Just out of interest, but all this *could* be done with normal command > line switches, and -mthreads is just a convenient shorthand, right? Or > does it do other stuff that can't be done any other way? I don't know for sure. I believe that you could do the same sort of thing with another set of command line switches, but GCC does a lot of internal work when searching for headers and libraries. So, IMO, sticking to the standard is the best way to go. Just for you know, the 'CL' compiler, the compiler that comes with Visual Studio, has a command line switch to select the right runtime library. When using '/MD' the compiler sets '_MT' define, tunning the Windows headers to use multi thread stuff. Also it links with the correct runtime library for multithreaded applications. The '-mthreads' on GCC mimics this behavior. Regards, Alessandro |