[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:34:14AM +0200, Thomas Salling wrote:
> Umiddelbart burde det jo virke, men outputtet er meget underligt.
> 
> CREATING THREAD: 0
> CREATING THREAD: 1
> THREAD 1 STARTING...
> THREAD 1 EXITING...
> CREATING THREAD: 2
> THREAD 2 STARTING...
> THREAD 2 EXITING...
> CREATING THREAD: 3
> THREAD 3 STARTING...
> THREAD 3 EXITING...
> THREAD 3 STARTING...
> THREAD 3 EXITING...
> 
> Hvor er min tråd 0 blevet af? Hvorfor bliver tråd 3 startet to gange?
> Så vidt jeg kan regne ud, så burde min thread_id altid være korrekt,
> da jeg giver det tal videre fra hvor jeg starter trådene.
Nope, for det er jo en pointer. Hvis tråden ikke bliver eksekveret med
det samme, så er den pointers værdi jo blevet inkrementeret.

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);
 }

-- 
/-----------------------------------------------------\
| 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] *