Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ace-users] ACE_Barrier

40 views
Skip to first unread message

Hubert Talbot

unread,
Nov 11, 2012, 11:36:09 AM11/11/12
to ace-...@list.isis.vanderbilt.edu
Hi,

I have some problem with ACE_Barrier...

Can you help me please?

Thanks.

Hubert


    ACE VERSION: 6.0.4

    HOST MACHINE and OPERATING SYSTEM:

        Windows 7

    TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
    COMPILER NAME AND VERSION (AND PATCHLEVEL):

    CONTENTS OF $ACE_ROOT/ace/config.h [if you use a link to a platform-
    specific file, simply state which one]:

        #define ACE_HAS_ICMP_SUPPORT 1
        #define __ACE_INLINE__ 1
        #include "ace/config-win32.h"

    CONTENTS OF $ACE_ROOT/include/makeinclude/platform_macros.GNU [if you
    use a link to a platform-specific file, simply state which one
    (unless this isn't used in this case, e.g., with Microsoft Visual
    C++)]:

    CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
    (used by MPC when you generate your own makefiles):

    LEVEL OF URGENCY (LOW, MEDIUM, or HIGH):

        HIGH

    AREA/CLASS/EXAMPLE AFFECTED:
[What example failed?  What module failed to compile?]

        Please, see below for the source code.

    DOES THE PROBLEM AFFECT:
        COMPILATION?
        LINKING?
            On Unix systems, did you run make realclean first?
        EXECUTION?
        OTHER (please specify)?
[Please indicate whether ACE, your application, or both are affected.]

        EXECUTION

    SYNOPSIS:
[Brief description of the problem]

        Program crashes.

    DESCRIPTION:
[Detailed description of problem.  Don't just say "<blah>
doesn't work, here's a fix," explain what your program does
to get to the <blah> state. ]

        I'm trying to use a barrier with threads having arguments.
        The program does not always work. Sometimes the program crashes.

    REPEAT BY:
[What you did to get the error; include test program or session
transcript if at all possible.  ]

    SAMPLE FIX/WORKAROUND:
[If available ]




Source code:

//http://oss.org.cn/ossdocs/ace_tao/ACE-5.4+TAO-1.4+CIAO-0.4/ACE/tutorials/Chap_4/ex07.html

#include "ace/Thread.h"
#include "ace/OS.h"
#include "ace/Synch.h"
#include "ace/Log_Msg.h"

static int number=0;
static int seed=0;

class Args
{
public:
    Args(ACE_Barrier *barrier, long i)
        : barrier_(barrier)
        , i_(i)
    {
    }
    ACE_Barrier *barrier_;
    long i_;
};

static void * worker(void *arguments)
{
    Args *arg= (Args*)arguments;
    ACE_DEBUG((LM_DEBUG,"Thread (%t) Created to do some work: %d\n", arg->i_));
    ::number++;

    //Work
    //ACE_OS::sleep(ACE_OS::rand()%2);

    //Exiting now
    ACE_DEBUG((LM_DEBUG,
        "\tThread (%t) Done! \n\tThe number is now: %d\n",number));
    //Let the barrier know we are done.
    ACE_DEBUG((LM_DEBUG,"Thread (%t) is exiting \n"));
    arg->barrier_->wait();
    return 0;
}


int main(int argc, char *argv[])
{
    if(argc<2)
    {
        ACE_DEBUG((LM_DEBUG,"Usage: <program_name> <number of threads>\n"));
        ACE_OS::exit(1);
    }

    int n_threads=ACE_OS::atoi(argv[1]);
    //ACE_DEBUG((LM_DEBUG,"Preparing to spawn %d threads",n_threads));
    //Setup the random number generator
    ACE_OS::srand(::seed);


    //Setup arguments for threads
    ACE_Barrier barrier(n_threads);
    Args arg1(&barrier, 1);
    Args arg2(&barrier, 2);
    Args arg3(&barrier, 3);
    Args arg4(&barrier, 4);

    Args vect[] = {arg1, arg2, arg3, arg4};

    //Spawn off n_threads number of threads
    for(int i=0; i<n_threads; i++){ if(ACE_Thread::spawn((ACE_THR_FUNC)worker,(void*)&vect[i],THR_DETACHED|THR_NEW_LWP)==-1)
        ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n"));
    }

    //Wait for all the other threads to let the main thread
    // know that they are done using hte barrier
    barrier.wait();

    return 0;
}




Douglas C. Schmidt

unread,
Nov 11, 2012, 11:38:35 AM11/11/12
to Hubert Talbot, ace-...@list.isis.vanderbilt.edu

Hi Hubert,

Thanks for using the PRF.
Several questions:

1. Why are you using trying to use this ancient source code with ACE 6.0.4?

> //http://oss.org.cn/ossdocs/ace_tao/ACE-5.4+TAO-1.4+CIAO-0.4/ACE/tutorials/
> Chap_4/ex07.html

2. Have you tried running the ACE_ROOT/tests/Barrier_Test.cpp regression
test in 6.0.4 to see how it works?

Thanks,

Doug
> _______________________________________________
> ace-users mailing list
> ace-...@list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/ace-users

Hubert Talbot

unread,
Nov 11, 2012, 1:57:28 PM11/11/12
to Douglas C. Schmidt, ace-...@list.isis.vanderbilt.edu
Hi Doug,

Thank you for the time you give me.

The two examples are slightly different.

Barrier_Test has only one 'args' with parameters while the example I provided (let's say 'A') has four.

I tested 'A' with only one parameter with spawn_n and it works perfectly.

'A' has a call to barrier.wait() while Barrier_Test has a call to ACE_Thread_Manager::instance ()->wait ();

Thanks

Hubert
________________________________________
De : ace-user...@list.isis.vanderbilt.edu [ace-user...@list.isis.vanderbilt.edu] de la part de Douglas C. Schmidt [sch...@dre.vanderbilt.edu]
Date d'envoi : 11 novembre 2012 11:38
À : Hubert Talbot
Cc : ace-...@list.isis.vanderbilt.edu
Objet : Re: [ace-users] ACE_Barrier

Douglas C. Schmidt

unread,
Nov 11, 2012, 6:20:49 PM11/11/12
to Hubert Talbot, ace-...@list.isis.vanderbilt.edu

Hi Hubert,

Could you please enhance the the ACE_ROOT/tests/Barrier_Test.cpp
regression test in 6.0.4 so that it manifests the problem that you're
having?

Thanks,

Doug

Johnny Willemsen

unread,
Nov 13, 2012, 8:47:28 AM11/13/12
to Hubert Talbot, ace-...@list.isis.vanderbilt.edu
Hi,

I have integrated your extension on linux but there the test just
doesn't exit. Can you report this in bugzilla, something to look at later.

Johnny

On 11/13/2012 02:26 PM, Hubert Talbot wrote:
> Hi Doug,
>
> Here is an enhanced Barrier_Test.cpp from ACE 6.1.6; the behaviour was the same with version 6.0.4.
>
> However, I found my problem.
>
> In the code provided with the PRF, it happens that one Args object is destroyed before the thread terminates. In the enhanced version of Barrier_Test.cpp, objects are created dynamically and deleted at the end of the thread. This fixes the problem.
>
> I don't know if the enhanced Barrier_Test.cpp can be useful now...
>
> Sorry for the inconvenience.
>
> Thanks.
>
> Hubert
>
>
>
>
> -----Message d'origine-----
> De : sch...@dre.vanderbilt.edu [mailto:sch...@dre.vanderbilt.edu]
> Envoyé : 11 novembre 2012 18:21
> À : Hubert Talbot
> Cc : ace-...@list.isis.vanderbilt.edu
> Objet : Re: RE : [ace-users] ACE_Barrier
0 new messages