Home > Archive > Unix Programming > January 2008 > Can single-threaded gcc be used for writing multi-threaded apps?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can single-threaded gcc be used for writing multi-threaded apps?
|
|
| Viatly 2008-01-17, 7:14 pm |
| I 'd like to know whether single-threaded gcc can be used for:
1. Writing multithreaded C app ( gcc file.c -pthread ).
2. Writing multithreaded C++ app ( g++ file.cpp -pthread ).
I will be very pleased with answers more detailed than just 'yes' and
'no'.
OpenBSD 4.2, gcc 3.3.5 (propolice)
| |
| arahne 2008-01-17, 7:14 pm |
| Viatly wrote:
> I 'd like to know whether single-threaded gcc can be used for:
> 1. Writing multithreaded C app ( gcc file.c -pthread ).
> 2. Writing multithreaded C++ app ( g++ file.cpp -pthread ).
Short answer: YES.
But just linking it with -phread library won't make it magically
multithreaded.
I suggest you read this tutorial.
http://www.yolinux.com/TUTORIALS/Li...sixThreads.html
Intel C/C++ compiler does have autovectorization, and
there you can really "just recompile" with -parallel
switch. In reality, this will mostly work for simple
initialization loops, not for complex code blocks
where you want it.
In any case, there is no free lunch and some extra
work is always required.
Dušan Peterc
http://www.arahne.si
| |
| Viatly 2008-01-17, 7:14 pm |
| On Jan 17, 10:34 pm, arahne <ara...@arahne.si> wrote:
> Viatly wrote:
>
> Short answer: YES.
However the fact that gcc is single-threaded means that gcc was build
with --enable-threads option off; this option enables C++ exception
handling for multi-threaded code. Does it mean that I should not use
exceptions in C++ code? But even if I don't myself, some parts of the
standard library could do it, e.g. new() throws bad_alloc.
Also, how could you comment this:
[citation]
4. All C++ code compiled by gcc 3.X configured with --disable-threads.
The final program is actually multi-threaded.
Undetectably broken. It might work, or it might not, on any
particular run. The most basic problem is that C++ exception handling
will not work properly. Up the stack from there, standard C++ library
resources might get trashed.
[/citation]
Citated from http://gcc.gnu.org/ml/libstdc++/2001-10/msg00024.html
|
|
|
|
|