Forums

How can I use CreateThread in the main() function on ADSP TS101S

Started by Nicrosoft April 23, 2004
It seems that I can not use main() if I want to comile a exe project 
with VDK support. For the default entry function is run() for the new 
thread.  I want to creat threads in the main() when I need and to
destroy this  thread when it is useless. Can I use the functions for
thread like  this?

The following is the linux thread code. 
///////////////////////////////////////
void* thread_entry (void* data)
{      
       ...    // do something.
       return NULL; 

}  

int main (void)
{
      pthread_t  new_thread;
     int data = 2;
     pthread_create ();
     pthread_join (new_thread, NULL); 

}
Nicrosoft wrote:

> It seems that I can not use main() if I want to comile a exe > project with VDK support. For the default entry function is run() > for the new > thread. I want to creat threads in the main() when I need and to > destroy this thread when it is useless. Can I use the functions > for > thread like this? > > The following is the linux thread code. > /////////////////////////////////////// > void* thread_entry (void* data) > { > ... // do something. > return NULL; > > } > > int main (void) > { > pthread_t new_thread; > int data = 2; > pthread_create (); > pthread_join (new_thread, NULL); > > }
Yes, you can create and destroy threads. However, you deal with lots of administration (execution time and memory allocations/deallocations). It might be preferable to create all threads in the beginning and then just "stop" and "restart" them as appropriate. What you need in any case is an administrating thread which takes the decisions about when creation or destruction of a thread have to take place and which initiates the work. To make things easy, just create a new project with VDK support, then on the VDK panel select a thread type and a boot thread which initially is running. Let its run() method serve as your main() function. Bernhard
Thanks a lot!. I will try...


Bernhard Holzmayer <holzmayer.bernhard@deadspam.com> wrote in message news:<1377326.iuDj2GbEUE@holzmayer.ifr.rt>...
> Nicrosoft wrote: > > > It seems that I can not use main() if I want to comile a exe > > project with VDK support. For the default entry function is run() > > for the new > > thread. I want to creat threads in the main() when I need and to > > destroy this thread when it is useless. Can I use the functions > > for > > thread like this? > > > > The following is the linux thread code. > > /////////////////////////////////////// > > void* thread_entry (void* data) > > { > > ... // do something. > > return NULL; > > > > } > > > > int main (void) > > { > > pthread_t new_thread; > > int data = 2; > > pthread_create (); > > pthread_join (new_thread, NULL); > > > > } > > Yes, you can create and destroy threads. However, you deal with lots > of administration (execution time and memory > allocations/deallocations). It might be preferable to create all > threads in the beginning and then just "stop" and "restart" them as > appropriate. > > What you need in any case is an administrating thread which takes > the decisions about when creation or destruction of a thread have > to take place and which initiates the work. > > To make things easy, just create a new project with VDK support, > then on the VDK panel select a thread type and a boot thread which > initially is running. Let its run() method serve as your main() > function. > > Bernhard