[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Mærkeligt problem med threads



On Fri, Aug 08, 2003 at 11:50:35AM +0200, Klaus S. Madsen wrote:
> Noget i flg. stil burde virke ret meget bedre:
> 
>  for( i=0 ; i<NUM_THREADS; i++ ) 
>  {
>   printf("CREATING THREAD: %d\n", i);
>   int * mem = malloc(sizeof(int));
>   *mem = i
>   pthread_create(&threads[i], NULL, fetch_start, (void*)mem);
>  }
Spade Klaus... En noget pænere løsning:


for (=0 ; i<NUM_THREADS; i++ ) 
{
 printf("CREATING THREAD: %d\n", i);
 pthread_create(&threads[i], NULL, fetch_start, (void*)i);
}

Og så for at få thread id'et ud i fetch_start:

void *fetch_start(void * threadid)
{
 printf("THREAD %d STARTED...\n", (int)threadid);
}
 
-- 
/-----------------------------------------------------\
| Klaus S. Madsen      | "Failure is not an option... |
| ICQ: 45400164        |  It comes bundled with your  |
| www.hjernemadsen.org |  Microsoft products!"        |
\-----------------------------------------------------/


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *