std::launch::asyc crashing Intellisense, possible bug in future, and problems with async()

  • Thread starter Thread starter LaughingManProductions_GW
  • Start date Start date
L

LaughingManProductions_GW

Guest
Hello, I have been attempting to create a test program with multi-threading using async in order to return back data from the completed threads however I am running into a problem due to Intellisense I believe. There are actually two problems here, the first is the subject of the title of this post, the definition of the launch namespace in future may have a bug in it that creases Intellisense when you attempt to forward define the usage of that namespace.


For example, typing:

using std::launch::async

into a program crashes Intellisense for me in Visual Studio 2013.

When looking up the definition of launch in the future file I found that MSVS stated there was an error on line 55 which contains this code around it:

enum launch { // names for launch options passed to async
async = 0x1,
deferred = 0x2,
any = async | deferred, // retained
sync = deferred
}


The error is that on the line any = async | deferred, that the value of any must have a constant value. The red line is on the bitwise OR.


I am not sure if that is related at all to my problem though. For whatever reason async does not seem to be working for me. It keeps telling my that there is no instance of an overloaded async that matches my function parameters. Here is my entire code for my example program:

#include <iostream>
#include <thread>
#include <string>
#include <cstdlib>
#include <ctime>
#include <future>
#include "random.h"

using std::thread;
using std::bind;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::ref;
using std::future;
using std::async;
using std::to_string;
using std::launch::async;

class Bank
{
public:
Bank(int init_depo, float wamount)
{
bAMoney = init_depo;
bAWAmount = wamount;
}

void dMoney(int monay)
{
bPDeposit = monay;
}

void cWAmount(float wamount)
{
bAWAmount = wamount;
}

void wMoney()
{
bPWithdrawl = bAMoney * bAWAmount;
}

void procPEVents()
{
if (bPDeposit - bPWithdrawl < bPDeposit)
{
bPWithdrawl -= bPDeposit;
bAMoney -= bPWithdrawl;
}

else
{
bPDeposit -= bPWithdrawl;
bAMoney += bPDeposit;
}

bPWithdrawl = 0.0f;
bPDeposit = 0;
}

int getMoney()
{
return bAMoney;
}

private:
int bAMoney; //Bank Account Money
float bAWAmount; //Bank Account Withdrawl Ammount
float bPWithdrawl; //Pending withdrawl
int bPDeposit; //Pending deposit
};

class exec_funcs
{
public:
exec_funcs()
{

}

string runBAccounts(Bank _bank, thread t1, thread t2, thread t3, int dAmount, float wAmount)
{
bool bTRunning = true;
bool bFSuccess = true;
int x = 0;

while (bTRunning)
{
t1 = thread(bind(&Bank::dMoney, ref(_bank), dAmount));
t2 = thread(bind(&Bank::wMoney, ref(_bank)));
t3 = thread(bind(&Bank::procPEVents, ref(_bank)));

t1.join();
t2.join();
t3.join();

//cout << "Income: " << pChoice1 << endl;
//cout << "Expenses: " << pChoice1 * pChoice2 << endl;
//cout << "Total Account Value for month " << x << ": " << b1.getMoney() << endl;
//system("Pause");

dAmount = Random(0.05f, 0.75f);
wAmount = Random(100, 900);
_bank.cWAmount(wAmount);

if (_bank.getMoney() < 500)
{
bTRunning = false;
}

else if (x > 100)
{
bTRunning = false;
bFSuccess = true;
}

else
{
x++;
}
}

if (!bFSuccess)
{
return "The account dropped below a value of $500 after " + to_string(x) + " months!";
}

else
{
return "Your account has a total value of $" + to_string(_bank.getMoney()) + " after " + to_string(x) + " months!";

}
}
};


int main()
{
//bool bTInterrupt = false
int pIChoice1, pIChoice2 = 0;
float pFChoice1, pFChoice2 = 0.0f;

thread bank_thread1, bank_thread2, bank_thread3, bank_thread4, bank_thread5, bank_thread6;
future<string> fStr1, fStr2;

srand(time(0));

cout << "Welcome to the LMPGames Financial Success Thread Simulator" << endl;
system("Pause");


pFChoice1 = Random(0.05f, 0.75f);
pIChoice1 = Random(780, 50000);

//Create bank account
Bank b1 = Bank(pIChoice1, pFChoice1);

pFChoice2 = Random(0.05f, 0.75f);
pIChoice2 = Random(780, 50000);

//Create bank account
Bank b2 = Bank(pIChoice2, pFChoice2);

pIChoice1 = Random(100, 900);
pIChoice2 = Random(100, 900);

fStr1 = async(launch::async,&exec_funcs::runBAccounts, b1, bank_thread1, bank_thread2, bank_thread3, pIChoice1, pFChoice1);
fStr2 = async(launch::async, &exec_funcs::runBAccounts, b2, bank_thread4, bank_thread5, bank_thread6, pIChoice1, pFChoice1);

cout << fStr1.get() << endl;
cout << fStr2.get() << endl;

system("Pause");

return 0;
}






"I thought what I would do was, Id pretend I was one of those Deaf-Mutes...Or should I?" -- Laughing Man ______ Laughing Man Productions² Entertainment and Gaming Network

Continue reading...
 
Back
Top