K. Frank | 1 Jun 02:20 2010
Picon

How to get started with mingw multi-threaded programming

Hello All -

How might I best approach multi-threaded programming with mingw32?

I'm looking for a balance of ease of getting started and functionality /
stability.  (This is for experimental, rather than production programming,
so occasional flakiness would be tolerable, but frequent flakiness would
get pretty annoying.)

I saw a mention of an MSYS pthreads package in "MSYS rebuild project
complete!"

   http://news.gmane.org/gmane.comp.gnu.mingw.user

   Cesar and Keith are already working on these:
   =============================================
   mingw32-gcc & family
   mingw32-mpfr
   mingw32-pthreads-w32   <-- *** should I try using this? ***

Provided installation and configuration isn't too troublesome, I would
probably prefer using a pthreads wrapper over native windows threading
calls.  Would MSYS pthreads be a good choice?

In the mingw wiki:

   http://www.mingw.org/wiki/Use_the_thread_library

a brief discussion about "_beginthreadex" and "CreateThread" seems
to recommend _beginthreadex.  (Also, looking at the function signatures,
(Continue reading)

Tatsh | 1 Jun 11:01 2010
Picon

Re: How to get started with mingw multi-threaded programming


K. Frank wrote:
> Hello All -
> 
> How might I best approach multi-threaded programming with mingw32?
> 
> I'm looking for a balance of ease of getting started and functionality /
> stability.  (This is for experimental, rather than production programming,
> so occasional flakiness would be tolerable, but frequent flakiness would
> get pretty annoying.)
> 
> I saw a mention of an MSYS pthreads package in "MSYS rebuild project
> complete!"
> 
>    http://news.gmane.org/gmane.comp.gnu.mingw.user
> 
>    Cesar and Keith are already working on these:
>    =============================================
>    mingw32-gcc & family
>    mingw32-mpfr
>    mingw32-pthreads-w32   <-- *** should I try using this? ***
> 
> 
> Provided installation and configuration isn't too troublesome, I would
> probably prefer using a pthreads wrapper over native windows threading
> calls.  Would MSYS pthreads be a good choice?
> 
> In the mingw wiki:
> 
>    http://www.mingw.org/wiki/Use_the_thread_library
(Continue reading)

Tor Lillqvist | 1 Jun 11:56 2010
Picon
Picon

Re: How to get started with mingw multi-threaded programming

> There are other options for portable threads too, such as QThread (from Qt),
> Boost::thread, and OpenMP.

And I should point out that also GLib has a thread API (which uses the
C library and Win32 APIs on Windows, i.e. no pthreads-win32 involved).
In case you prefer a plain C library...

All this said, unless you are 100% sure you need to write C or C++
code, why not consider a more modern, garbage collected (as if that
was something modern, hah...), safe, language and environment, Java
and C# being the most obvious choices?

--tml

------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

K. Frank | 1 Jun 17:28 2010
Picon

Re: How to get started with mingw multi-threaded programming

Hello Tor -

On Tue, Jun 1, 2010 at 5:56 AM, Tor Lillqvist <tml@...> wrote:
>> There are other options for portable threads too, such as QThread (from Qt),
>> Boost::thread, and OpenMP.
>
> And I should point out that also GLib has a thread API (which uses the
> C library and Win32 APIs on Windows, i.e. no pthreads-win32 involved).
> In case you prefer a plain C library...

If I understand correctly, GLib is a large framework library that has as
part of it a thread api.  For my current purposes, I would prefer to stay
away from a big framework, and stay close to plain-vanilla C++.  (For
example, even though I am also working with Qt -- which has a thread
api -- my goal here is to do some plain-vanilla, non-Qt multi-threaded
programming.)

> All this said, unless you are 100% sure you need to write C or C++
> code, why not consider a more modern, garbage collected (as if that
> was something modern, hah...), safe, language and environment, Java
> and C# being the most obvious choices?

On this side note...

Oh, I don't need to write C++, rather I prefer to.  I find C++ to be the
most expressive mainstream language (but, of course, tastes vary).
Also, the original java threading model was somewhat naive compared
to pthreads, and really didn't gain full functionality until java 5.  So I
tend to give pthreads (and the win32 api) points for maturity.

(Continue reading)

K. Frank | 1 Jun 17:25 2010
Picon

Re: How to get started with mingw multi-threaded programming

Hi Tatsh -

On Tue, Jun 1, 2010 at 5:01 AM, Tatsh <ddrtist@...> wrote:
>
> K. Frank wrote:
>>
>> How might I best approach multi-threaded programming with mingw32?
>> I'm looking for a balance of ease of getting started and functionality /
>> stability.
>> ...
>>    mingw32-pthreads-w32   <-- *** should I try using this? ***
>> ...
> I have a little info on this on the Gentoo wiki. Native calls are perfectly
> fine (except for probably some very new ones). However, if you plan to port
> your app to POSIX environments (including OS X), right now pthreads-win32 will
> cover almost all bases then you won't even have to blink for the most part
> when it comes to building for other OS's.

I think I will try starting with a pthreads wrapper for convenience and
familiarity.

> ...
> You can work with that to get pthreads-win32 installed on a Windows install
> just as much.

What precisely is mingw32-pthreads-w32 (mentioned in my original
posting)?  Is it the same as the pthreads-win32 you mention, but
maybe "cerified for use" with mingw32?

> Just treat your MSYS environment like a 'real' UNIX environment.
(Continue reading)

Greg Chicares | 1 Jun 18:37 2010
Picon
Picon

Re: How to get started with mingw multi-threaded programming

On 2010-06-01 15:25Z, K. Frank wrote:
> 
> I skimmed the Boost.Thread documentation.  I'm confused.  I thought
> that Boost was supposed to be standard C++ and not platform specific.

Boost develops libraries for inclusion in future versions of the
C++ standard. Some of their code can be written in standard C++;
the pseudorandom number library is an example. Other libraries
have a set of platform-specific implementations, much like qt.
For example, the boost filesystem library must behave differently
on platforms that have different rules to determine which file
names are valid and how directories are traversed.

Once a library is accepted into the standard, implementors need
to find a (possibly platform specific) way to implement it, but
programmers can just use it.

> Since C++ (currently) makes no reference to threads,

Chapter 30 of the 2010 final draft standard describes a thread
library that is (naturally) close to boost's.

> how can Boost
> provide thread capabilities without drilling down to native os calls, and
> having to provide different versions for different platforms?  I didn't notice
> anything in the documentation about platform dependence or supported
> platforms.

http://www.boost.org/doc/libs/1_43_0/doc/html/thread/acknowledgements.html
| The scheme for dividing the platform-specific implementations
(Continue reading)

K. Frank | 1 Jun 20:55 2010
Picon

Re: How to get started with mingw multi-threaded programming

Hello Greg -

On Tue, Jun 1, 2010 at 12:37 PM, Greg Chicares <gchicares@...> wrote:
> On 2010-06-01 15:25Z, K. Frank wrote:
>>
>> I skimmed the Boost.Thread documentation.  I'm confused.  I thought
>> that Boost was supposed to be standard C++ and not platform specific.
>
> Boost develops libraries for inclusion in future versions of the
> C++ standard.
> ...
> Chapter 30 of the 2010 final draft standard describes a thread
> library that is (naturally) close to boost's.

Ah, that reminds me:  gcc has significant support for c++0x, and
some of the gnu docs show that thread support is pretty much
there:

   http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html

Would anybody know if

    g++ -std=c++0x

will give me decent thread support with mingw?  (I'm currently
using g++ version 4.4.1.  What if I upgrade to version 4.5?)

> ...
> Once a library is accepted into the standard, implementors need
> to find a (possibly platform specific) way to implement it, but
(Continue reading)

Keith Marshall | 1 Jun 21:46 2010
Picon
Picon

Re: How to get started with mingw multi-threaded programming

On Tuesday 01 June 2010 16:25:34 K. Frank wrote:
> What precisely is mingw32-pthreads-w32 (mentioned in my original
> posting)?  Is it the same as the pthreads-win32 you mention, but
> maybe "cerified for use" with mingw32?

They are one and the same.  We repackage our own build, from upstream 
sources (unmodified), simply to honour our obligations under the GPL, 
because our GCC-4.5 requires POSIX threads support.  Our package name 
differs from upstream, because it must comply with the conventions we 
have adopted for mingw-get's dependency resolver.

--

-- 
Regards,
Keith.

------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

(Continue reading)

K. Frank | 2 Jun 03:19 2010
Picon

Re: How to get started with mingw multi-threaded programming

Hello Keith and List -

On Tue, Jun 1, 2010 at 3:46 PM, Keith Marshall
<keithmarshall@...> wrote:
> On Tuesday 01 June 2010 16:25:34 K. Frank wrote:
>> What precisely is mingw32-pthreads-w32 (mentioned in my original
>> posting)?  Is it the same as the pthreads-win32 you mention, but
>> maybe "certified for use" with mingw32?
>
> They are one and the same.  We repackage our own build, from upstream
> sources (unmodified), simply to honour our obligations under the GPL,
> because our GCC-4.5 requires POSIX threads support.  Our package name
> differs from upstream, because it must comply with the conventions we
> have adopted for mingw-get's dependency resolver.

In a previous posting I asked:

   Would anybody know if

      g++ -std=c++0x

   will give me decent thread support with mingw?  (I'm currently
   using g++ version 4.4.1.  What if I upgrade to version 4.5?)

It appears that linux version of g++ 4.4 supports threads, but the
mingw version doesn't.  For example, see:

   http://www.eggheadcafe.com/software/aspnet/35840730/summary-of-c0x-feature.aspx

A little odd: "#include <thread>" compiles (with -std=c++0x), but
(Continue reading)

K. Frank | 5 Jun 03:08 2010
Picon

Re: How to get started with mingw multi-threaded programming

Hello All -

Apparently no c++0x threads yet...

On Tue, Jun 1, 2010 at 9:19 PM, K. Frank <kfrank29.c@...> wrote:
> Hello Keith and List -
> ...
> In a previous posting I asked:
>
>   Would anybody know if
>
>      g++ -std=c++0x
>
>   will give me decent thread support with mingw?  (I'm currently
>   using g++ version 4.4.1.  What if I upgrade to version 4.5?)
>
> It appears that linux version of g++ 4.4 supports threads, but the
> mingw version doesn't.  For example, see:
>
>   http://www.eggheadcafe.com/software/aspnet/35840730/summary-of-c0x-feature.aspx
>
> A little odd: "#include <thread>" compiles (with -std=c++0x), but
> "std::thread t;" doesn't.  The guts of the header file "thread' are
> protected by:
>
>   #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
>
> That is (more directly), will upgrading to mingw g++ 4.5 give me
> std::thread (using -std=c++0x)?
> ...
(Continue reading)

Tor Lillqvist | 5 Jun 08:58 2010
Picon
Picon

Re: How to get started with mingw multi-threaded programming

> From scattered comments on the web it appears that gthreads
> is a gnu wrapper for pthreads (and maybe some other threading
> libraries)

You seem to be confusing things here. As far as I know there is
nothing called "gthreads". There is a GNU "portable" thread library,
GNU Pth, http://www.gnu.org/software/pth/ . At least that web page
doesn't mention Windows at all, though. And frankly, for Unix-like
systems, there already is the pthread API which is widely implemented,
so I don't immediately see the need for GNU Pth. But I probably am
missing something.

Then there is GThread, a thread API that is part of GLib. On Unix-like
systems it uses the underlying pthread API (which then uses the actual
underlying thread system calls, if different). On Windows, it uses the
(Microsoft) C library's _beginthreadex() function to start threads and
the Win32 API for mutexes etc. Note that GLib can be built on Windows
either with MinGW or Microsoft's compiler, there is nothing
MinGW-specific about it.

>  that hasn't been incorporated into mingw (or cygwin) yet
> (even though there is a gthread-win32.c and people have built glib
> for windows).

I don't understand what you think should be incorporated into MinGW,
and why. MinGW is not supposed to be a POSIX emulation layer, so I
think it would be wrong to incorporate pthreads-win32
(http://sourceware.org/pthreads-win32/ ) into MinGW. (Assuming the
pthreads-win32 maintainers would even approve; if they wouldn't, it
would be even more wrong.)
(Continue reading)

Tor Lillqvist | 5 Jun 09:38 2010
Picon
Picon

Re: How to get started with mingw multi-threaded programming

Let me add that in the names GLib and GThread, the G doesn't really
stand for GNU, it stands for GIMP (because GIMP was the application
for which GLib and GTK+ were originally developed). But usually the
GIMP connection is not even mentioned, and the names aren't expanded.

Sure, GIMP nowadays means "GNU Image Manipulation Program" (originally
the G meant "General"). But that doesn't mean one could say that
GLib's GThread API would be "the GNU thread library" or something like
that.

There is also gnulib which is a totally different thing. And glibc, of course.

Finaly, the whole subject of this threads shows a misunderstanding.
There is no, and won't hopefully be any, separate MinGW thread
programming model. "How to get started with Windows multi-threaded
programming" would have been a better subject.

--tml

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
(Continue reading)

K. Frank | 5 Jun 15:35 2010
Picon

Re: How to get started with mingw multi-threaded programming

Hi Tor -

Thanks for clearing up some of the history.  I have a couple of
unimportant comments.

On Sat, Jun 5, 2010 at 2:58 AM, Tor Lillqvist <tml@...> wrote:
>> From scattered comments on the web it appears that gthreads
>> is a gnu wrapper for pthreads (and maybe some other threading
>> libraries)
>
> You seem to be confusing things here. As far as I know there is
> nothing called "gthreads"...

Yes.  I didn't really know what to call it.  The main reason I called
it "gthreads" is because of the line of (preprocessor) code:

   #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)

in:

   ...\lib\gcc\mingw32\4.5.0\include\c++\thread

the header (supplied as part of mingw's g++) for "experimental" c++0x
threading support.

> ...
> Then there is GThread, a thread API that is part of GLib. On Unix-like
> systems it uses the underlying pthread API (which then uses the actual
> underlying thread system calls, if different). On Windows, it uses the
> (Microsoft) C library's _beginthreadex() function to start threads and
(Continue reading)


Gmane