How best to create multiple threads in MINGW

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

How best to create multiple threads in MINGW

veegee

Hi:

Relatively new MINGW user (using CodeLite + MINGW + wxWidgets +
wxFormBuilder) - few days.

I am trying to create a multi-threaded app in MINGW (g++).  What is the best
way to do this? From doing search on the internet I can see that there are a
lot of people doing multi-threaded programming in MINGW but I came across no
code snippets for creating/managing a new thread.  A code example will be
extremely helpful.

I have found the Pthreads library inside the MINGW distribution but this
looks like an "external" library to MINGW.  With the PThreads library I seem
to be able to create threads (sample code below that compiles and links but
has not been tested).  Is Pthreads the best way to go?   What are the
alternatives?  Is there a built-in (i.e. non-external, MING officially
supported) way to do this?

PThreads sample code:
#include <pthreads.h>
..
void XXX::method1{
..
pthread_t new_thread_data;
pthread_create(&new_thread_data, 0, &func, &args);
..
}
(I have not found how best to link PThreads library statically instead of
using the .dll - if you know how to do that that will be very helpful too).

Appreciate your help.
--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32475668.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee

>From doing search on the internet I am coming to the conclusion that
pthreads-win32 is the way to go, since the C++ library extensions for
threading support are not fully implemented on some platforms (such as
Windows).   Actually I don't know if even those standards have been
finalized yet..

Any thought ??
--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32476014.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

Rinrin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

? 2011/9/16 8:58, veegee ??:
>
>> From doing search on the internet I am coming to the conclusion
>> that
> pthreads-win32 is the way to go, since the C++ library extensions
> for threading support are not fully implemented on some platforms
> (such as Windows).   Actually I don't know if even those standards
> have been finalized yet..
>
> Any thought ??
specific to C++, Would you try boost::thread ?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOcqIUAAoJEIopQjIpgMdEk/YIAJo+Rws/jFxJm8+UCmKB+Y3Q
TFDRz2goF4THoeYIJOu+TIS5ucsT6w49/3pV9jFNjnTK/GI3QQCo6HKjdSiUd6jV
U9ZXAQY9ovRG7iqsCZTZnY97q/f1OLY6P93MLN/hw+Wyg+vH9QbIwFv8J8IQpbI8
bMC8o/nnlceAXs5eEnN51JCZrjaNjO8sWI5kM1qYPzIjytJw5HnGIdoMcgZEjfsi
Jfgw8Bt8U23Jjv+H6Aop86JvY+JtdiO4eNN7lJXlohKT3i8Kd7EDSdr53UA0aPL7
xz+i+51HTnvOxRprF4MWQKjzb1BwitBRJL/mhjst0big1KMUubt1mpSlkFq3yB4=
=RZY8
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

lrn-2
In reply to this post by veegee
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 16.09.2011 3:12, veegee wrote:
>
> Hi:
>
> Relatively new MINGW user (using CodeLite + MINGW + wxWidgets +
> wxFormBuilder) - few days.
>
> I am trying to create a multi-threaded app in MINGW (g++).  What is
> the best way to do this?
There is no such way.
There is a number of thread-libraries, here are some of them:
1) pthreads-w32 (you've found it already)
2) winpthreads (mingw-w64's answer to pthreads-w32)
3) w32pth (w32 port of pth, which is a GNU'ish thread library)

Also - std::thread, or something like that (apparently, a C++ concept,
not sure which part of C++ standard it belongs to)

And then there is CreateThread() function from W32API, as well as
_beginthread() and _beginthreadex() functions from CRT (both are
w32-only CRT extensions and are, obviously, based on CreateThread())

And then any half-decent general-purpose library/framework (glib, qt,
boost, apr) offers some kind of threading functionality (which is
usually implemented roughly the same way as (1), (2) or (3) are).

And then there is a concept of non-threaded concurrency, but i only
know one framework that offers this kind of functionality (it's
Twisted), and it's kinda difficult to implement on top of W32 (due to
difficulties with selecting/polling on heterogeneous I/O objects).

So everything really depends on complexity of the threading you want
to implement in your application, and your portability requirements.
For very simple threading you might be able to stick to CreateThread()
and its friends, #ifdef'ing it as W32-only.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOcrPhAAoJEOs4Jb6SI2CwDeAH/A9egKkrLxJKWKj1NTAngdxg
/c3rxnVWfPM8fVvtf76MqeBiqfjx44cajE2AcTgCmZe7bUqbm8toSPf2fMsxuqTc
mWnJIKbNQcoxwYivWwUDECSxYB2BsQlgJWTwgApzx/HEHpV43WYvaga6GidmewLP
Y0tooY0CXxSSJS5031E0vMqSEdTzB+QVA2fUvNmArXTI6xDD6VkxVsECcXbnTcb1
PFrWoXZDLWe571HMDQwbNT6oW/BZxQhU+cgklVXLo+0DHcIHxPqS25OgWqmxW3dv
MmdtFUvfUaSzhGfDCgvPLrCdzeP1Z1Do0oEU/ToQvbQDFjmWIZH072fkipfMcEA=
=gF5Q
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

Tor Lillqvist
> Is there a built-in (i.e. non-external, MING officially supported) way to do this?

Well, if you look at MinGW as what it actually is, i.e. a *WIndows*
compiler that uses the Windows-specific *Microsoft* C  library  (i.e.
not some kind of make-Windows-look-like-Linux thingie), then the most
natural API to use would be CreateThread(), or preferably its
counterpart in the C library, _beginthreadex(). (Using the latter
avoids potential problems like leaks of resources.)

Use the libraries that export the POSIX thread API only if your code
is supposed to be portable to POSIX, and you want to avoid ifdefs.

--tml

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee
In reply to this post by Rinrin

>> specific to C++, Would you try boost::thread ?

Not really familiar with Boost - I need to look into it more.  People seem
to like it from what I have read.

--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32485481.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee
In reply to this post by lrn-2

>>There is no such way.
>>There is a number of thread-libraries, here are some of them:
>>1) pthreads-w32 (you've found it already)
>>2) winpthreads (mingw-w64's answer to pthreads-w32)
>>3) w32pth (w32 port of pth, which is a GNU'ish thread library)
>>
>>Also - std::thread, or something like that (apparently, a C++ concept,
>>not sure which part of C++ standard it belongs to)

Is the C++ standard (C++00x or something like that) available in mingw g++?
I would have gone that route since all platforms will (sooner or later)
later support it.
Don't know the level of threading support implemented so far for this std.

>>And then there is CreateThread() function from W32API, as well as
>>_beginthread() and _beginthreadex() functions from CRT (both are
>>w32-only CRT extensions and are, obviously, based on CreateThread())

Would prefer to NOT go this route since I do want to write cross-platform
code.

>>And then any half-decent general-purpose library/framework (glib, qt,
>>boost, apr) offers some kind of threading functionality (which is
>>usually implemented roughly the same way as (1), (2) or (3) are).

I need to look into these - esp. Boost.  I am already using wxWidgets for
the gui
portion.. hesitant to add too many dependencies

>>And then there is a concept of non-threaded concurrency, but i only
>>know one framework that offers this kind of functionality (it's
>>Twisted), and it's kinda difficult to implement on top of W32 (due to
>>difficulties with selecting/polling on heterogeneous I/O objects).

Sounds interesting.   I do have multiple threads created and running
working with PThreads and now I need to figure out how best to create the
communication between the parent and child.


--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32485566.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee
In reply to this post by Tor Lillqvist


>> Use the libraries that export the POSIX thread API only if your code
>> is supposed to be portable to POSIX, and you want to avoid ifdefs.

I do want to make the code portable to Mac and Linux
--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32485583.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

Daniel Klíma
In reply to this post by veegee
2011/9/17 veegee <[hidden email]>:

>
>>>There is no such way.
>>>There is a number of thread-libraries, here are some of them:
>>>1) pthreads-w32 (you've found it already)
>>>2) winpthreads (mingw-w64's answer to pthreads-w32)
>>>3) w32pth (w32 port of pth, which is a GNU'ish thread library)
>>>
>>>Also - std::thread, or something like that (apparently, a C++ concept,
>>>not sure which part of C++ standard it belongs to)
>
> Is the C++ standard (C++00x or something like that) available in mingw g++?
> I would have gone that route since all platforms will (sooner or later)
> later support it.
> Don't know the level of threading support implemented so far for this std.
>
>>>And then there is CreateThread() function from W32API, as well as
>>>_beginthread() and _beginthreadex() functions from CRT (both are
>>>w32-only CRT extensions and are, obviously, based on CreateThread())
>
> Would prefer to NOT go this route since I do want to write cross-platform
> code.
>
>>>And then any half-decent general-purpose library/framework (glib, qt,
>>>boost, apr) offers some kind of threading functionality (which is
>>>usually implemented roughly the same way as (1), (2) or (3) are).
>
> I need to look into these - esp. Boost.  I am already using wxWidgets for
> the gui
> portion.. hesitant to add too many dependencies

Hello.

If you're using WxWidgets, then classes and functions for
multithreading are present:
http://docs.wxwidgets.org/trunk/group__group__class__threading.html //classes
http://docs.wxwidgets.org/trunk/group__group__funcmacro__thread.html
//functions and macros

And they should be take care of portability. (AFAIK it uses native
WinAPI for threading.)

Is there a reason why not to use them? (I currently don't use them so
might not be aware of limitations of Wx implementation)

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee

>> If you're using WxWidgets, then classes and functions for
>> multithreading are present:
>> http://docs.wxwidgets.org/trunk/group__group__class__threading.html //classes
>> http://docs.wxwidgets.org/trunk/group__group__funcmacro__thread.html
>> //functions and macros
>>
>> And they should be take care of portability. (AFAIK it uses native
>>WinAPI for threading.)
>>
>>Is there a reason why not to use them? (I currently don't use them so
>>might not be aware of limitations of Wx implementation)

I did think of using those since I am using wxWidgets after all for GUI.  But I have this
crazy notion of having the same app as a console (command-line) app (from the
same source code but built differently) -and didn't want the console version to use
any external libraries.

So (at least for now) what I have settled on is: 
    - create my own wrapper class for the thread creation which hides the
        OS specific thread functions  - the thread creation calls _beginthreadex
        in windows and pthread_create in flavors of Unix (god knows what I'll
        need to use on Mac but Mac may be Unix compatible)

I have this working but have only written enough code to create and run the thread
i.e. have not written abstract versions of thread exit, cancel etc. yet.  And I have
the GUI version (using wxWidgets) and Console version (no wxWidgets)
building from the same source code and running multiple threads.

It is not easy to OS-abstract the threading APIs.  The signature of the thread start
function in Unix (pthreads)  is "void* func(void*)", whereas in Windows (_beginthreadex)
it is "unsigned int func(void*)".  Plus the create functions also return data differently -
pthread_create will return data in a structure of type pthread_t from where
getting the thread_id is ill-defined. Windows _beginthreadex returns a
 "uintptr_t" handle but has the decency to specifically also return a thread_id.

Venu P. Gopal

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

lrn-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18.09.2011 19:14, Venu Gopal wrote:

> Plus the create functions also return data differently -
> pthread_create will return data in a structure of type pthread_t
> from where getting the thread_id is ill-defined. Windows
> _beginthreadex returns a "uintptr_t" handle but has the decency to
> specifically also return a thread_id.
>
You should read [1], just in case.
[1] http://lists-archives.org/mingw-users/21403-pthread_t-declaration.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOdgzKAAoJEOs4Jb6SI2CwV9YIAIKvLyOb519ohrCCmyKjbCjp
2QWbtjAw2OgkFC37Thq1W59QZ81s36hgznis9BE98XpJEGHgQCKftB9daxzQLOP4
d0C6H4EGO8nD3opnUc/rAptGGdEgCg/Ev2PiEsLsdZCHXtEg2la3W7X/Ub8Ffvo7
W35Bsfq4KXimPzBrlDySvZEIEAzCiWVLCR0Gp9LwyG1Ev+gtr5PgaZGvJKxegtdp
Pk0KCrarBWPCNaFQc3gzr2F5xN6S0pMIjXkxeE/e5G+DOwUIvCVyd2tq53qziHFM
sSOkyesqpbHnFsvxfdFW8KmoEVcfoRM7q3nsrWYlQRPsyYlZccweAl6IaQeOQCA=
=XPiI
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

Eran Ifrah
In reply to this post by veegee
On Sun, Sep 18, 2011 at 6:14 PM, Venu Gopal <[hidden email]> wrote:

>
>>> If you're using WxWidgets, then classes and functions for
>>> multithreading are present:
>>> http://docs.wxwidgets.org/trunk/group__group__class__threading.html
>>> //classes
>>> http://docs.wxwidgets.org/trunk/group__group__funcmacro__thread.html
>>> //functions and macros
>>>
>>> And they should be take care of portability. (AFAIK it uses native
>>>WinAPI for threading.)
>>>
>>>Is there a reason why not to use them? (I currently don't use them so
>>>might not be aware of limitations of Wx implementation)
>
> I did think of using those since I am using wxWidgets after all for GUI.
> But I have this
> crazy notion of having the same app as a console (command-line) app (from
> the
> same source code but built differently) -and didn't want the console version
> to use
> any external libraries.
>
> So (at least for now) what I have settled on is:
>     - create my own wrapper class for the thread creation which hides the
>         OS specific thread functions  - the thread creation calls
> _beginthreadex
>         in windows and pthread_create in flavors of Unix (god knows what
> I'll
>         need to use on Mac but Mac may be Unix compatible)
>

Why not using pthread for all three OSs?

Its not that you will be able to distribute your application without
any external DLL ... (you will need at least mingw10.dll) so packing
another DLL (i.e. pthreadGC32.dll) should not be a problem, not to
mention it will simplify your code

The pthreadGC32.dll is already distributed that bundled in codelite

> I have this working but have only written enough code to create and run the
> thread
> i.e. have not written abstract versions of thread exit, cancel etc. yet.
> And I have
> the GUI version (using wxWidgets) and Console version (no wxWidgets)
> building from the same source code and running multiple threads.
>
wxThread is part of the wxBase module, so if you are using wxWidgets
as multilib, you can distribute only this DLL which is significatly
smaller than the rest of the framework.
Note that if you are using the wxWidgets that comes with codelite, it
won't help you much, since I built it as monolithic DLL (i.e. it
includes all modules - GUI, Base, Network  and others into a single
DLL)

> It is not easy to OS-abstract the threading APIs.  The signature of the
> thread start
> function in Unix (pthreads)  is "void* func(void*)", whereas in Windows
> (_beginthreadex)
> it is "unsigned int func(void*)".  Plus the create functions also return
> data differently -
> pthread_create will return data in a structure of type pthread_t from where
> getting the thread_id is ill-defined. Windows _beginthreadex returns a
>  "uintptr_t" handle but has the decency to specifically also return a
> thread_id.
>
> Venu P. Gopal
>
> ------------------------------------------------------------------------------
> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
> http://p.sf.net/sfu/rim-devcon-copy2
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> 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
> Also: mailto:[hidden email]?subject=unsubscribe
>



--
Eran Ifrah
Author of the cross platform, open source C++ IDE: http://www.codelite.org
TimeWarden, a parental control software: http://www.smartkoders.com

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee
In reply to this post by lrn-2

Thanks, LRN.  Looks like this is about 'pthreads-w32' implementation of pthread_t , but nevertheless, interesting reading...
I was referring to actual pthread_t implementations on uinx (right now I am not using pthreads-w32 and my wrapper does not
return any pthread_t like structure to the caller).

BTW, in that article, puzzled as to the author's opinion about the pthread functions returning pthread_t by value - a pointer is
passed to the pthread_t structure, which means both the caller and the callee can make modifications to the structure.



------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee
In reply to this post by Eran Ifrah
>> Why not using pthread for all three OSs?
>>
>>Its not that you will be able to distribute your application without
>>any external DLL ... (you will need at least mingw10.dll) so packing
>>another DLL (i.e. pthreadGC32.dll) should not be a problem, not to
>>mention it will simplify your code
>>
>>The pthreadGC32.dll is already distributed that bundled in codelite

Eran:  Agreed, for the GUI.  

Right now I am building my own application framework to create
multi-threaded apps. These apps could be simple console apps or GUI apps.
For GUI apps, I don't mind external DLLs.  For the console apps I wish to have
a simple executable with no "dll/.so" dependencies - put the darn thing somewhere
and just execute it ( note: this is just my desire, that is all).

>>wxThread is part of the wxBase module, so if you are using wxWidgets
>>as multilib, you can distribute only this DLL which is significatly
>>smaller than the rest of the framework.
>>Note that if you are using the wxWidgets that comes with codelite, it
>>won't help you much, since I built it as monolithic DLL (i.e. it
>>includes all modules - GUI, Base, Network  and others into a single
>>DLL)

Thanks for that idea.  It could come in use in the future, but right now,
 'lightness' is not  a factor, it's more of having 'dependencies'.  Again,
not very strong feelings - I simply like simplicity.

BTW, I have been using CodeLite now for two weeks may be (?) and I am
TOTALLY impressed by the job you did on that.  AWESOME !!!!
(I am not easily impressed, by the way :-).

 Venu P. Gopal





------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

K. Frank
Hi Venu!

On Sun, Sep 18, 2011 at 3:03 PM, Venu Gopal <[hidden email]> wrote:

>>> Why not using pthread for all three OSs?
>>>
>>>Its not that you will be able to distribute your application without
>>>any external DLL ... (you will need at least mingw10.dll) so packing
>>>another DLL (i.e. pthreadGC32.dll) should not be a problem, not to
>>>mention it will simplify your code
>>>
>>>The pthreadGC32.dll is already distributed that bundled in codelite
>
> Eran:  Agreed, for the GUI.
>
> Right now I am building my own application framework to create
> multi-threaded apps. These apps could be simple console apps or GUI apps.
> For GUI apps, I don't mind external DLLs.  For the console apps I wish to
> have
> a simple executable with no "dll/.so" dependencies - put the darn thing
> somewhere
> and just execute it ( note: this is just my desire, that is all).
> ...

To follow up on an earlier suggestion in this thread:  Why not use the standard
std::thread facilities of the upcoming c++0x standard?  (Unless you want to
restrict yourself to c, rather than c++, which I don't think is an issue, based
on the preceding discussion.)  That would seem to be the "forward-looking" way
to go, and you won't have to write your own os-dependent threading wrappers.

std::thread works out-of-the-box with recent g++ versions on linux.
It is alleged
to work on windows using mingw-w64, a project distinct from, but
similar to mingw:

   http://sourceforge.net/mailarchive/message.php?msg_id=28014252

It is also easy to patch mingw to get std::thread working (basically relying on
pthreads-win32 to take advantage of the pthreads implementation of std::thread
that ships with recent versions of gcc, at the cost of becoming dependent on
the pthreads dll).  You can see my earlier thread on this here:

   http://sourceforge.net/mailarchive/message.php?msg_id=26533138

Good support for std::thread exists in g++ today, and it's only going to get
better and more widespread, because it's a central part of the new standard.

> ...
>  Venu P. Gopal

Good luck.


K. Frank

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee

Hi K. Frank:

>> To follow up on an earlier suggestion in this thread:  Why not use the
>> standard
>> std::thread facilities of the upcoming c++0x standard?  (Unless you want
>> to
>> restrict yourself to c, rather than c++, which I don't think is an issue,
>> based
>> on the preceding discussion.)  That would seem to be the
>> "forward-looking" way
>>to go, and you won't have to write your own os-dependent threading
wrappers.
>> std::thread works out-of-the-box with recent g++ versions on linux.
>> It is alleged to work on windows using mingw-w64, a project distinct
>> from, but
>> similar to mingw:
>> http://sourceforge.net/mailarchive/message.php?msg_id=28014252

This is absolutely what I want to do.   As you indicate, support for c++0x
standard is
available generally on linux, but not on Windows or Mac.   As soon as it is
supported officially, I will throw my wrappers into the garbage can and
happily re-code to use
std:thread.

>> It is also easy to patch mingw to get std::thread working (basically
>> relying on
>> pthreads-win32 to take advantage of the pthreads implementation of
>> std::thread
>> that ships with recent versions of gcc, at the cost of becoming dependent
>> on
>> the pthreads dll).  You can see my earlier thread on this here:
>> http://sourceforge.net/mailarchive/message.php?msg_id=26533138
>> K. Frank

Nice work on using pthreads-win32 to get a std::thread working on mingw.  
Since I am
stubbornly insisting on not including pthread-win32 (which, by the way, has
nothing to do
with its technical merits - I think it is a great piece of work), I can't do
what you describe
in your patch article.  Perhaps I should re-write my wrappers to look like
std::thread? Or
help you with mods to your files to eliminate the dependency on
pthreads-win32?


--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32491027.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

K. Frank
Hello Venu!

I have taken the liberty of copying this post to the mingw-w64 list,
as it's relevant there, as well.

On Sun, Sep 18, 2011 at 4:18 PM, veegee <[hidden email]> wrote:

>
> Hi K. Frank:
>
>>> To follow up on an earlier suggestion in this thread:  Why not use the
>>> standard
>>> std::thread facilities of the upcoming c++0x standard?  (Unless you want
>>> to
>>> restrict yourself to c, rather than c++, which I don't think is an issue,
>>> based
>>> on the preceding discussion.)  That would seem to be the
>>> "forward-looking" way
>>>to go, and you won't have to write your own os-dependent threading
> wrappers.
>>> std::thread works out-of-the-box with recent g++ versions on linux.
>>> It is alleged to work on windows using mingw-w64, a project distinct
>>> from, but
>>> similar to mingw:
>>> http://sourceforge.net/mailarchive/message.php?msg_id=28014252
>
> This is absolutely what I want to do.   As you indicate, support for c++0x
> standard is
> available generally on linux, but not on Windows or Mac.

If you're willing to use mingw-w64, I believe that std::thread *is* supported
on windows.

> As soon as it is
> supported officially, I will throw my wrappers into the garbage can and
> happily re-code to use
> std:thread.

I believe that the mingw-w64 support of std::thread is official, but perhaps
someone from the mingw-w64 list could comment on this so that I don't
put words in anyone's mouth.

>>> It is also easy to patch mingw to get std::thread working (basically
>>> relying on
>>> pthreads-win32 to take advantage of the pthreads implementation of
>>> std::thread
>>> that ships with recent versions of gcc, at the cost of becoming dependent
>>> on
>>> the pthreads dll).  You can see my earlier thread on this here:
>>> http://sourceforge.net/mailarchive/message.php?msg_id=26533138
>>> K. Frank
>
> Nice work on using pthreads-win32 to get a std::thread working on mingw.
> Since I am
> stubbornly insisting on not including pthread-win32 (which, by the way, has
> nothing to do
> with its technical merits - I think it is a great piece of work), I can't do
> what you describe
> in your patch article.

Well, it depends on what your issue with pthreads-win32 is.  As I understand
it, the mingw-w64 team (who should correct me if I'm wrong) wanted 1) to
have the pthread handle be a scalar type (as it is in most (all?) unix
implementations, but not in pthreads-win32), and 2) avoid some of the
licensing issues that arise with pthreads-win32.  So they wrote their own
pthreads implementation for windows (winpthreads I think they call it).  If
mingw-w64's winpthreads resolves any of your issues with pthreads-win32,
you can get std::thread out of the box with mingw-w64 (as I understand it,
not having tried it myself yet).

> Perhaps I should re-write my wrappers to look like
> std::thread? Or
> help you with mods to your files to eliminate the dependency on
> pthreads-win32?

I have implemented a native windows version of std::thread for g++
(mingw and mingw-w64).  It is native in the sense that it the various
std::thread facilities are implemented directly in terms of the windows
api without going through a pthreads-like layer (and, in particular, through
neither pthreads-win32 nor winpthreads).  You can see some discussion
of it here:

   http://sourceforge.net/mailarchive/message.php?msg_id=26417080

Note that this implementation would require vista or later, because, among
other things, it uses windows condition variables.

It has the advantage that it doesn't use pthreads, so it gets rid of a layer
between std::thread and the underlying windows os.  But it has the
disadvantage that it doesn't use (or implement) pthreads, so it doesn't
provide a threading solution for code that uses pthreads.  (And, of course,
lots of code uses pthreads, and hardly any code uses std::thread (yet).)

Right now this implementation exists as a locally patched versions of
mingw and mingw-w64, but has not been integrated into the gcc (or
mingw / mingw-w64) code base or packaged as patches that can be
applied to that code base.

If this sort of implementation (which is less mature than the pthreads-based
solutions) would be of use to you, I'd be happy to work with you to help
adapt it to your needs.  But in the best of all worlds, I'd hope that we could
structure any such effort to be of use to a broader audience.

Best.


K. Frank

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

veegee

Hi K. Frank:

>> I have taken the liberty of copying this post to the mingw-w64 list,
>> as it's relevant there, as well.

No Problem.  Honestly, I am not familiar with mingw-w64 project and the
relation between
mingw and mingw-w64.  At least intitially I thought it was 64-bit version of
minGW.

>> Well, it depends on what your issue with pthreads-win32 is.  

No issue at all - I like it, in fact - but don't want any external libs in
my console app.

>> As I understand it, the mingw-w64 team (who should correct me if I'm
>> wrong) wanted 1) to
>> have the pthread handle be a scalar type (as it is in most (all?) unix
>> implementations, but not in pthreads-win32), and 2) avoid some of the
l>> icensing issues that arise with pthreads-win32.  So they wrote their own
>> pthreads implementation for windows (winpthreads I think they call it).
>> If
>> mingw-w64's winpthreads resolves any of your issues with pthreads-win32,
>> you can get std::thread out of the box with mingw-w64 (as I understand
>> it,
>> not having tried it myself yet).

Do you think it is a possibility to just port the mingw-64 code to mingw ?
Not familiar
with any licensing issues involved - I am assuming both are open sourced
(MINGW runtime is public domain, other parts GPL, don't know about
mingw-w64)

>> I have implemented a native windows version of std::thread for g++
>> (mingw and mingw-w64).  It is native in the sense that it the various
>> std::thread facilities are implemented directly in terms of the windows
>> api without going through a pthreads-like layer (and, in particular,
>> through
>> neither pthreads-win32 nor winpthreads).  You can see some discussion
>> of it here:  
>> http://sourceforge.net/mailarchive/message.php?msg_id=26417080
>> Note that this implementation would require vista or later, because,
>> among
>> other things, it uses windows condition variables.
>> It has the advantage that it doesn't use pthreads, so it gets rid of a
>> layer
>> between std::thread and the underlying windows os.  But it has the
>> disadvantage that it doesn't use (or implement) pthreads, so it doesn't
>> provide a threading solution for code that uses pthreads.  (And, of
>> course,
>> lots of code uses pthreads, and hardly any code uses std::thread (yet).)

Let me look at the discussion you are referring to.  Was your implementation
before
that of the mingw-w64 team ? Any way to bring those implementations
together?
For code written using pthreads, there is already pthreads-w32 that can
be used- so I wouldn't be concerned about that.  But I would be concerned
about two
different implementations between minGW and mingw-w64 (again, not fully
comprehending
the relation between the two).

>> Right now this implementation exists as a locally patched versions of
>> mingw and mingw-w64, but has not been integrated into the gcc (or
>> mingw / mingw-w64) code base or packaged as patches that can be
>> applied to that code base. If this sort of implementation (which is less
>> mature than the pthreads-based solutions) would be of use to you,
>> I'd be happy to work with you to help adapt it to your needs.  

I would like to try it out if I can do it as app level code (like my own
wrappers)
rather than patching mingw.

>> But in the best of all worlds, I'd hope that we could
>> structure any such effort to be of use to a broader audience.

Of course.  But perhaps we should go off-line with any discussion on
collaboration rather than
over burden folks with email???

Venu P. Gopal


--
View this message in context: http://old.nabble.com/How-best-to-create-multiple-threads-in-MINGW-tp32475668p32491869.html
Sent from the MinGW - User mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

Earnie Boyd
In reply to this post by veegee
On Sat, 17 Sep 2011 09:13:12 -0700 (PDT), veegee wrote:

>
>
> >> Use the libraries that export the POSIX thread API only if your
> >> code is supposed to be portable to POSIX, and you want to avoid
> >> ifdefs.
>
> I do want to make the code portable to Mac and Linux

The best thing about using a third party library such as Boost is that
they take care of the differences in platforms and give you the ability
to write code without the headache of the differences in platforms.

Earnie

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How best to create multiple threads in MINGW

NightStrike
In reply to this post by veegee
On Sun, Sep 18, 2011 at 8:22 PM, veegee <[hidden email]> wrote:

>
> Hi K. Frank:
>
>>> I have taken the liberty of copying this post to the mingw-w64 list,
>>> as it's relevant there, as well.
>
> No Problem.  Honestly, I am not familiar with mingw-w64 project and the
> relation between
> mingw and mingw-w64.  At least intitially I thought it was 64-bit version of
> minGW.

That's just one part of it.  We also add additional features.

>>> Well, it depends on what your issue with pthreads-win32 is.
>
> No issue at all - I like it, in fact - but don't want any external libs in
> my console app.
>
>>> As I understand it, the mingw-w64 team (who should correct me if I'm
>>> wrong) wanted 1) to
>>> have the pthread handle be a scalar type (as it is in most (all?) unix
>>> implementations, but not in pthreads-win32), and 2) avoid some of the
> l>> icensing issues that arise with pthreads-win32.  So they wrote their own
>>> pthreads implementation for windows (winpthreads I think they call it).
>>> If
>>> mingw-w64's winpthreads resolves any of your issues with pthreads-win32,
>>> you can get std::thread out of the box with mingw-w64 (as I understand
>>> it,
>>> not having tried it myself yet).
>
> Do you think it is a possibility to just port the mingw-64 code to mingw ?
> Not familiar
> with any licensing issues involved - I am assuming both are open sourced
> (MINGW runtime is public domain, other parts GPL, don't know about
> mingw-w64)

The big thing that was have is the winpthreads library, which is under
very active development.  Kai can comment more about it.  It should
solve your probelms.

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
MinGW-users mailing list
[hidden email]

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
Also: mailto:[hidden email]?subject=unsubscribe
12