Question

I am trying to invoke two independent threads by using Asynchronous Agent Library (AAL) as included in in C++ (refer also to here for AAL description http://msdn.microsoft.com/en-us/library/dd492627.aspx). The Agents Library provides alternatives to shared state by letting you connect isolated components through an asynchronous communication model that is based on dataflow instead of control flow. Dataflow refers to a programming model where computations are made when all required data is available; control flow refers to a programming model where computations are made in a predetermined order.

As I do not want to wait for arbitrary data from one agent, I wanted to use Concurrency::send() and Concurrency::try_receive(). However, I have problems implementing the try_receive method (documentation can be found here http://msdn.microsoft.com/de-de/library/dd470874.aspx).

My current implementation:

ISource<bool>& _source;    
Concurrency::try_receive(_source, &Received,ITarget<CPlant*>::filter_method())

with CPlant as my data to be sent back to the agent where the _source-Message comes from. Agent1 sends a simple boolean "true" and Agent2 (that includes the code mentioned above) responses with the CPlant class. This is working with Concurrency::receive(), but I don't want to block the further execution of the current agent.

Do you have a clue why I get compiling errors like

1>c:\users\robert\tum\da\src\sim\anlagensim\anlagensim\main.cpp(57): error C2782: 'bool Concurrency::try_receive(Concurrency::ISource<_Type> &,_Type &,const ITarget<_Type>::filter_method &)' : template parameter '_Type' is ambiguous
1>          c:\program files\microsoft visual studio 10.0\vc\include\agents.h(16553) : see declaration of 'Concurrency::try_receive'
1>          could be 'int *'
1>          or       'bool'
1>c:\users\robert\tum\da\src\sim\anlagensim\anlagensim\main.cpp(57): error C2780: 'bool Concurrency::try_receive(Concurrency::ISource<_Type> &,_Type &)' : expects 2 arguments - 3 provided

?

Thanks in advance for your help!

Was it helpful?

Solution 2

I did another approach by using OpenMP that nicely support data sharing and thread management very easily.

#include <omp.h>
...

#pragma omp parallel shared(Simulation, cout) default(none) num_threads(3)
{
    #pragma omp sections nowait
    {
        #pragma omp section 
        {
        ...
        }

        #pragma omp section 
        {
        ...
        }

        #pragma omp section
        {
        ...
        }
    }
}

Be advised to use /openmp switch while using Visual C++.

OTHER TIPS

I've never done anything with this library, however looking at the function signature you're presumably trying to match:

template <
   class _Type
>
bool try_receive(
   ISource<_Type> & _Src,
   _Type & _value,
   typename ITarget<_Type>::filter_method const& _Filter_proc
);

All three of the parameters to try_receive expect the same _Type. Looking at the way you're calling it, you're passing in ISource<bool> for the _Src parameter (so expecting _Type to be bool where as for the _Filter_proc parameter you're passing in ITarget<CPlant*> (so epecting _Type to be CPlant*). Since bool != CPlant*, the compiler is getting confused and failing to resolve the function and trying to fall back on the other overloads for the function, which is why you're getting the strange error.

Since I've not used the library, I can't tell you what you should be passing, but I'd guess that probably you should be using ISource<CPlant*> (or _Type as CPlant rather than CPlant*).

Note, that the second parameter is also of type _Type, so Received needs to use the same template type as the other parameters (it's unclear from your question what type this parameter is currently).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top