Can single-threaded gcc be used for writing multi-threaded apps? - BSD

This is a discussion on Can single-threaded gcc be used for writing multi-threaded apps? - BSD ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Can single-threaded gcc be used for writing multi-threaded apps?

  1. Can single-threaded gcc be used for writing multi-threaded apps?

    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)

  2. Re: Can single-threaded gcc be used for writing multi-threaded apps?

    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/Lin...ixThreads.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

  3. Re: Can single-threaded gcc be used for writing multi-threaded apps?

    On Jan 17, 10:34 pm, arahne wrote:
    > 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.


    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

+ Reply to Thread