boost-thread


bind function with return value


I am studying thread-pool with asynchronous I/O. I've tried to bind a function with return value, however, it failed. Can anyone please help (the code which starts with "ioService.post")?
Thank you very much.
#include <vector>
#include <ppl.h>
#include <iostream>
#include <chrono>
#include <boost/asio/io_service.hpp>
#include <boost/thread/thread.hpp>
#include <boost/phoenix/phoenix.hpp>
#include <boost/function.hpp>
using namespace std;
typedef vector<double> Vector;
typedef vector<Vector> Matrix;
class myClass {
private:
int num;
Matrix a;
Vector z;
public:
myClass(int n) :
num(n), a(num, Vector(2)) {}
Vector subFun(int n) {
Vector b(2, 0);
b[0] = n;
b[1] = n+num;
//body: to be implemented
return b;
}
void mainFun() {
Matrix z;
Vector w;
boost::asio::io_service ioService;
boost::thread_group threadpool;
boost::asio::io_service::work work(ioService);
for (int i = 0; i < std::thread::hardware_concurrency(); i++) {
threadpool.create_thread(
boost::bind(&boost::asio::io_service::run, &ioService)
);
}
for (int i = 0; i < num; i++) {
ioService.post(boost::phoenix::bind(&myClass::z, this) =
boost::phoenix::bind(&myClass::subFun, this, i));//OK
ioService.post(boost::phoenix::bind(&myClass::a[i], this) =
boost::phoenix::bind(&myClass::subFun, this, i));//FAIL
ioService.post(boost::phoenix::bind(w) =
boost::phoenix::bind(&myClass::subFun, this, i));
//local variable w -->FAIL
}
ioService.stop();
threadpool.join_all();
}
Matrix getA() {
return a;
}
};

Related Links

bind function with return value
configure: error: cannot not find the flags to link with Boost thread on Ubuntu 14
Boost thread overrides value of member variables
Boost thread interrupt and join without blocking the calling thread
Simple boost::thread usage crash
How to create a thread using Boost
Hiredis, libev and boost:threads
boost::thread and memory model
Error while linking program to boost thread library
boost::thread and creating a pool of them!

Categories

HOME
dotnetrdf
crystal-reports
cil
wsdl
raspbian
sbt-assembly
console
spring-cloud-contract
multiple-monitors
cloudflare
riak
jquery-terminal
riak-ts
android-toolbar
jcl
mousewheel
tweets
statusbar
nsmenuitem
binutils
header-files
azure-servicebus-queues
myob
jflex
non-deterministic
onesignal
skmaps
nesc
rowcount
modelandview
google-guava-cache
hashcat
discord.net
meta-raspberrypi
polyfills
jupyter-console
xbim
distributed-transactions
paho
bids
nsjsonserialization
chunked-encoding
tiddlywiki
rhel6
windows-95
cdk
paas
build-process
system.web.ui.webcontrols
gradle-eclipse
uwp-maps
date-format
supportmapfragment
amazon-kcl
git-rebase
difference
oai
js-cookie
coypu
callstack
stackframe
jai
ejabberd-saas
java-melody
snmp4j
suffix-array
dbsetup
jstack
xenocode
confusion-matrix
layered
va-list
android-contextmenu
cgpath
dropdownlistfor
socketstream
symfony-2.0
deploying
die
paintcomponent
recordset
gwt-2.2-celltable
odbc-sql-server-driver

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App