D
Daniel
When I use the CreateThread API method, what do I need to do when I want to
pass more than one parameter where LPVOID lpParameter is passed?
Daniel
pass more than one parameter where LPVOID lpParameter is passed?
Daniel
When I use the CreateThread API method, what do I need to do when I
want to pass more than one parameter where LPVOID lpParameter is
passed?
I didn't realize I even had any control over whether the variable is
stack or heap -allocated. What determines how it is allocated?
SvenC said:Hi Daniel.
Please, start reading a book about C++ before starting to think
about writing multi threaded apps!!!
If you want to avoid thinking about memory managment go with C#.
To get you started:
struct MyData
{
int id;
std:string name;
};
void foo()
{
MyData d; // this is allocated on the stack
MyData* pd = new MyData; // this is allocated on the heap
d.id = 42;
d.name = "I will die when this scope is left";
pd->id = 43;
pd->name = "I live on the stack, so care about calling delete somewhere";
// if you would store the address of d and use it after foo is left
// you would access random data
// you can pass around pd in your process as you like but be sure
// to synchronize access when multiple threads are around and think
// about the correct place where you call delete to avoid leaking memory
}
Daniel said:What function do I use to allow the thread function to temporarily
relinguish control of the cpu so that another thread could get a time
slice of the cpu?
Daniel said:What function do I use to allow the thread function to temporarily
relinguish control of the cpu so that another thread could get a time slice
of the cpu?
Daniel said:I thought if it was a long process then it would put a freeze on the user
interface so that the user could not interact with it.
Daniel said:Wow. I didn't realize it would be that easy. It even requires only one
simple parameter. Thanks.
Mark Salsbery said:Daniel said:Wow. I didn't realize it would be that easy. It even requires only one
simple parameter. Thanks.
It's simple, and rarely necessary
I recommend NOT getting in the habit of using it. It is NOT a thread
synchronization function. There are special objects for that
Cheers,
Mark
Daniel said:What are the special objects?
I just did some research. It seems that automatic stack variables are
basically variables of local scope that is allocated automatically
and on a stack. It's what Sven said is opposed to a heap allocated
variable. Is that not correct?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.