473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Passing a parameter to a thread (boost)

Hi,

I create my threads like this:

for(int j = 0; j < 5; j++)
{
boost::thread *thr = new boost::thread(worker_func);
threads.add_thread(thr);
}

How would i go about passing a parameter into the worker function? If
possible i would like to pass a structure in.

Thanks for any help,

Jack
Dec 2 '07 #1
2 3704
JackC wrote:
Hi,

I create my threads like this:

for(int j = 0; j < 5; j++)
{
boost::thread *thr = new boost::thread(worker_func);
threads.add_thread(thr);
}

How would i go about passing a parameter into the worker function? If
possible i would like to pass a structure in.
Use Boost.Bind, or similar.
Dec 2 '07 #2
On Dec 2, 11:15 pm, JackC <jeche...@gmail.comwrote:
I create my threads like this:
for(int j = 0; j < 5; j++)
{
boost::thread *thr = new boost::thread(worker_func);
threads.add_thread(thr);
}
How would i go about passing a parameter into the worker
function? If possible i would like to pass a structure in.
The worker function is a boost::function, so you can pass it
pretty much anything that's copiable. Be aware that it will be
copied, however; if you want to access it later in the parent
thread (say after a join), then you need to pass a pointer (or
maybe a reference).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: AMS | last post by:
I am trying to create a thread to execute a script for me and then display the output in notepad. What is happening is when I call the CreateThread method and pass in the Routine and Parameter...
2
by: muser | last post by:
How can I pass the parameter " long part_num, into a case statement. Case statement follows the function CheckDigit. i.e. CheckDigit( something, temp1 ); Thank you for your help in advance. ...
12
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
4
by: Lighter | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; using namespace boost; void hello() { cout << "Hello world, I'm a thread!" << endl; }
3
by: Gary Wessle | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; class waiter { public: waiter(); void waiting(); void preform();
4
by: Gary Wessle | last post by:
Hi given the Boost thread example here http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/thread/example/thread.cpp the code below attempts to run the example thread while...
8
by: asit | last post by:
How do I pass parameters to created thread..here is the code(but it can't pass data..it uses global variable) #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.