hello everyone,
i'm just trying to play around with some threads before makign a mulithreaded server for some purpose....
i read somewhere that if you have a static variable in a parent thread, you can access it from a child thread. i don't know how! here is a code snippet:
so, what i tried to do in teh above code is declare a static char * "stint" in my main method. when i spawn off a new thread, i would like to print out stint from the new thread.. (just to learn how to access static variables from a thread.)... was wondering if someone could suggest what i could do!
also, i'm not dealing with any synchronization yet! i will do that later.. i'm just trying to learn some stuff first!
thanks a lot! really appreciate any help you can give me!
drew.
i'm just trying to play around with some threads before makign a mulithreaded server for some purpose....
i read somewhere that if you have a static variable in a parent thread, you can access it from a child thread. i don't know how! here is a code snippet:
Code:
#include <iostream>
#include <process.h>
#include <conio.h>
unsigned int __stdcall test(void* param)
{
std::cout << "from within thread" << std::endl;
std::cout << "a is: " << *(static_cast<int*>(param)) << std::endl;
//std::cout<<"stint is: "<<::stint<<std::endl;
return 0;
}
int main()
{
std::cout<<"hi" << std::endl;
int a=44;
static char* stint="static char";
_beginthreadex(0, 0, test, &a, 0, 0);
_getch(); // Give the thread some time here...
return 0;
}
so, what i tried to do in teh above code is declare a static char * "stint" in my main method. when i spawn off a new thread, i would like to print out stint from the new thread.. (just to learn how to access static variables from a thread.)... was wondering if someone could suggest what i could do!
also, i'm not dealing with any synchronization yet! i will do that later.. i'm just trying to learn some stuff first!
thanks a lot! really appreciate any help you can give me!
drew.