473,320 Members | 2,202 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,320 software developers and data experts.

_beginthread on a class method

I have a class called cScale, I have made an array of scale objects and I
need to run a method of these objects as a new thread. This is my line of
code and I can't get it to run. I am still a little of a newbie to C++.
Scales is an array of scale objects and weighup is my method.

Scales[ScaleNum].thread = _beginthread( Scales[ScaleNum].WeighUp, 0, NULL);
Nov 17 '05 #1
2 2882
Altman wrote:
I have a class called cScale, I have made an array of scale objects and I
need to run a method of these objects as a new thread. This is my line of
code and I can't get it to run. I am still a little of a newbie to C++.
Scales is an array of scale objects and weighup is my method.

Scales[ScaleNum].thread = _beginthread( Scales[ScaleNum].WeighUp, 0, NULL);

You can't do it that way. The thread startup calls normally take a
void* pointer. I suggest you pass in a pointer to a structure
containing a "this" pointer to an instance of the class together some
data so it knows what function to actually execute.

/steveA

--
Steve Alpert
my email Fgrir_Nycreg @ vqk.pbz is encrypted with ROT13 (www.rot13.org)
and spaces

Nov 17 '05 #2
Steve Alpert <sr*@newsgroups.nospam> wrote:
Altman wrote:
I have a class called cScale, I have made an array of scale objects and I
need to run a method of these objects as a new thread. This is my line of
code and I can't get it to run. I am still a little of a newbie to C++.
Scales is an array of scale objects and weighup is my method.

Scales[ScaleNum].thread = _beginthread( Scales[ScaleNum].WeighUp, 0, NULL);

You can't do it that way. The thread startup calls normally take a
void* pointer. I suggest you pass in a pointer to a structure
containing a "this" pointer to an instance of the class together some
data so it knows what function to actually execute.


Actually, passing the 'this' pointer
itself should do. Something like this:

class my_thread {
public:
// ...
protected:
void thread_func();
private:
static void thread_func_(void* p)
{
my_thread* this_ = reinterpret_cast<my_thread*>(p);
this_->thread_func();
}
};

void start_thread(my_thread* thr)
{
_beginthread( &my_thread::thread_func_, 0, thr );
}
/steveA

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Nov 17 '05 #3

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
9
by: liangbowen | last post by:
As i konw, the only way to to terminate a thread started by _beginthread() is to user _endthread() (or return) inside the thread. now i started a thread(TodoThread), and created a listenning...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
6
by: dude | last post by:
I am trying to test out _beginthread() but I keep getting an error that: _beginthread : undeclared identifier I am using Visuall C++ with DotNET Studio and am on windows XP. Here is the...
5
by: JHoletzeck | last post by:
Is it possible to set the stack size for the thread created by BackgroundWorker like in the API call _beginthread? If not is the stack size a default or the one I set for the whole application?...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
3
by: shell6 | last post by:
I get a few errors building a prog with _beginthread. I have done the proper compile options and included libcmt.lib in linking, but I still get these errors: libcimtd.lib(streamb.obj) : error...
1
by: akoolb | last post by:
_beginthread( function, 0, (void*)(int)num); That's what I'm using, what I need to know is how can I send more than one parameter with it, I've spent a while searching and can't find the answer. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.