Subject: Re: [Mingw-users] Re: Multi-threaded programs
From: "Paul G." <[email-masked]>
To: [email-masked]
Cc: [email-masked], [email-masked], [email-masked]
Date: Wed, 09 Apr 2003 17:56:41 -0700

Hi again...

	Just poking my head in again...;-)

	I agree with Earnie, this is also applicable to Cygwins'  "-mno-cygwin" switch, so I have also expanded the 
distribution to include the Cygwin mailing list.

	I highly encourage original poster to subscribe to Mingw mailing list.

> I'm showing explicitly the output. Here is the linking sentence:
> 
> c++ -o Exefile -g3 -v -Wall -mno-cygwin -mthreads   << my objects >>
> -L(Directories) -lnetapi32 -lwsock32
> 
> So I don't call explicitly most of linking libraries.
> 
> Perhaps should I use g++ directly ?

	I should state that for me, it is assumed that you are indeed using "g++" as opposed to "c++".  Clearly that was an 
invalid assumption in this case.

	In that case, and in an attempt to avoid any other "false assumptions", let me restate, specifically:

	You should be using "g++", not "c++".  This is justified by the fact that by using "g++", you are eliminating one 
more avenue that "could" or "might only" result in an increase in confusion when it comes to support.

	As Danny has noted, do you have a small test case?

	If so, it would be appreciated if you posted such a thing as that would give us something to work with and 
eliminate any other "assumptions" that may currently exist in terms of building multi-threaded applications.

	Also, we have no idea which version of the GNU Compiler you are using or the .dll that is being invoked 
(runtime?) when your linking phase occurs.

	Other Assumptions:

		We can safely assume that for "Cygwin", the .dll most recently being used is cygwin1.dll
		We can safely assume that for "Mingw", the .dll most recently being used is mingwm10.dll

		I can state that mingwm10.dll is included as part of Cygwin install (/bin/mingwm10.dll).

		I can also state that if "-mno-cygwin" switch is used than it is quite likely that mingwm10.dll is
		being used	(when an app is linked).

		Finally, the assumption that the whole point behind using the "-mno-cygwin" switch, afaik, is to
		"disable/eliminate the inclusion of cygwin1.dll references at link time".

---

	Unless otherwise noted, any references/questions about which platform is being used will refer to the
	Microsoft Windows(R) NT4/SP6 OS.

"g++ -v"  will always give us the version number and, in some cases, the default linking behavior.

Cygwin --

	"g++ -v -mno-cygwin -mthreads"

$ g++ -v -mno-cygwin -mthreads
Reading specs from /usr/lib/gcc-lib/i686-pc-mingw32/3.2/specs
Configured with: /netrel/src/gcc-3.2-3/configure --enable-languages=c,c++,f77,java --enable-libgcj --enable-
threads=posix --with-system-zlib --enable-nls --without-included-gettext --enable-interpreter --disable-sjlj-exceptions
--disable-version-specific-runtime-libs --enable-shared --build=i686-pc-linux --host=i686-pc-cygwin --target=i686-pc-
cygwin --enable-haifa --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
--includedir=/nonexistent/include --libexecdir=/usr/sbin

Thread model: posix

[NOTE:  Thread Model is "posix", not "win32" -- This is a MAJOR DIFFERENCE in terms of what can be invoked 
"using" -mno-cygwin versus "not using" the "-mno-cygwin" switch).
...
If thread model is indeed, ie. "literally speaking", "the posix threading model" then "Win32 threading model" will not be 
invoked and any win32 thread model will (probably) not work.  The Cygwin folks know more about this aspect of 
thread model invocation than I do.  Indications, at least to me, right now, are that "the win32 thread model will not be 
invoked", even if -mno-cygwin switch is detected on the g++ command line.]

gcc version 3.2 20020927 (prerelease)

---

Mingw --

	"g++ -v -mthreads"

D:\src>g++ -v -mthreads
Reading specs from d:/mingw/bin/../lib/gcc-lib/mingw32/3.2.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --
prefix=/mingw --enable-threads --disable-nls --enable-languages=c++,f77,objc --disable-win32-registry
--disable-shared --enable-sjlj-exceptions

Thread model: win32

	[NOTE:  Thread Model = win32]

gcc version 3.2.2 (mingw special 20030208-1)

g++: no input files

---

	Other Things of Note:

	There is a major difference between the g++ version references.
	There is a major difference in what is being linked/checked using "-mno-cygwin"
	(under Cygwin w/"-mno-cygwin -mthreads") versus "what is being linked/checked"
	under the "Mingw" model w/"-mthreads".

---

	Final analysis:  If you want to use Cygwin w/"-mno-cygwin -mthreads", at this point, there is no guarantee that you 
will even have the proper threading model for your application(s).  If you want to use Mingw, you can be fairly safe in 
assuming that the win32 thread model is, at the very least, minimally supported.

	It is this analysis that indicates we need a small test program (for both Cygwin and Mingw I would assume) before 
we can offer more specifics in terms of the actual cause(s?) behind "why" the Win32 model of multi-threading is "not", 
apparently, "working for some".

	Paul G.

> 
> Ignasi Villagrasa.
> 
> Ranjit Mathew wrote:
> 
> >> It fails with and without -mthreads in compilation and linking.
> >>
> >> Here is the list of libraries linked in the application.
> >>
> >> -lnetapi32 -lwsock32 -lstdc++ -lmingwthrd -lmingw32 -lgcc
> >> -lmoldname -lmsvcrt -lmingwthr d -lmingw32 -luser32 -lkernel32
> >> -ladvapi32 -lshell32 -lmingwthrd -lmingw32 -lgcc -lmoldname
> >> -lmsvcrt
> >>
> >> What am I  going wrong ?
> >
> >
> > Why do you need to explicitly link in all these libraries?
> > (Or are you showing the final output of compiling with "g++ -v"?
> > BTW, you *are* compiling this with "g++" - not "gcc" - aren't you?)
> >
> > AFAICT, you just need to link in like:
> >
> > g++ -mthreads -o exename all-your-object-files -lws2_32 -lnetapi32
> >
> > Does this also not work?
> >
> > Ranjit.
> >
> > _________________________________________________________________
> > High ISD bills? Get a phone card. http://www.msn.co.in/webtelephony
> > Call US for just Rs. 5
> >
> >
> >
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> MinGW-users mailing list
> [email-masked]
> 
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/