This is the mail archive of the
mailing list for the GCC project.
Re: Basic Question on Building Multi-Threaded 'C' Apps with gcc
- From: Nick Maclaren <nmm1 at cus dot cam dot ac dot uk>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 29 Nov 2007 19:13:19 +0000
- Subject: Re: Basic Question on Building Multi-Threaded 'C' Apps with gcc
Frank Tufano <firstname.lastname@example.org> wrote:
> I am developing a multi-threaded application (written in 'C') on Linux
> on the AMD x86-64 platform. I would like to know what compile and link
> options I should be specifying to ensure that the application builds
> properly. (We are using the posix thread model). The only thread
> related option info I can find in the AMD x86-64 Options section of the
> online manual is the -mthreads option, which is for "thread-safe
> exception handling on `Mingw32'", which is not applicable. Below is my
> gcc version info and some system info.
This is a generic reply, and is not specific to gcc, but applies
to that as much as to anything.
If you are using threads as shared memory processes, and will be
doing relatively little interaction with explicit synchronisation,
then you shouldn't have to do much except keep the optimisation
down to a lowish level.
If you are writing genuinely parallel code, with interactions at
a low level, you may have to play every dirty trick in the book.
This is because (despite their claims), C and POSIX do not even
remotely support that, and C++ does not yet do so. As a result,
even the most "parallel friendly" compilers may not provide the
semantics you expect, or even usable ones.
For example, and this is a real problem, you can get time reversal
even on an x86 architecture system if one of the processors needs
to fix up a memory problem at just the wrong moment. Not just ECC,
but TLB misses. I am 95% sure that gcc doesn't generate the slow
code needed to ensure that doesn't cause trouble, and I can't see
any way that it can be completely avoided without that.
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Tel.: +44 1223 334761 Fax: +44 1223 334679