-
Threads in C++
Hey...
Okay here's the deal. I'm thinking of creating an IRC client, but the thing is.. i don't know what to use or how to make it so that it's waiting for incoming messages from the server AND sending whatever i type in at the same time. Any input is appreciated.. thanks :)
Regards
rezonax
---
CodePeople <-- if($needhelpwith=="programming") visit(codepeople);[
-
in response to the title,
_beginthread
-
Re: Threads in C++
Thanks a bunch.. do you know where i can read up on that function?
rezonax
-
if you have MSVC use the MSDN, borland builder has a library that has it.
if you don't have those,
unsigned long _beginthread( void( __cdecl *start_address )( void * ), unsigned stack_size, void *arglist );
Paramaters:
start_address
Start address of routine that begins execution of new thread
stack_size
Stack size for new thread or 0
arglist
Argument list to be passed to new thread or NULL
void _endthread(void)
used to terminate the thread created by begin thread.
use them like so
Code:
int counter = 0;
// this functio must be declaread in this format void myfunc(void*)
void ThreadFunc(void* v)
{
while(counter < 10000);
_endthread(); // must be called to cleanup after thread
}
main()
{
bool done = false;
// do not include the parentheses when passing the function to beginthread
_beginthread(ThreadFunc,0,NULL);
while(!done)
{
if(counter%1000)
printf("Counter:%d",counter);
}
return 0;
}
this shuld print the value of counter ten times