[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:
> Hej,
> 
> Jeg sidder og leger med tråde i C (GCC 2.95, 2.4.18), men der er noget som virkelig undrer mig. Jeg har forsøgt at lede på google for at se om 2.95 af gcc er bugget, men jeg har ikke fundet noget som relaterede til mit problem. Jeg håber I måske har oplevet noget lignende. Jeg paster lidt kode, men jeg håber I overlever. Jeg har skåret alt væk i et forsøg på at debugge.
> 
> Jeg starter mine tråde således:
> 
> ...
> 
>  pthread_t threads[NUM_THREADS];
>  int i;
> 
>  for( i=0 ; i<NUM_THREADS; i++ ) 
>  {
>   printf("CREATING THREAD: %d\n", i);
>   pthread_create(&threads[i], NULL, fetch_start, (void*)&i);
>  }
> 
>  for( i=0 ; i<NUM_THREADS ; i++ ) 
>   pthread_join(threads[i], NULL);
> 

Du genbruger i paa tvaers af traade. Dermed bliver output afhaengigt
af traadskedulering og kan variere fra gang til gang. Proev at bruge
pthread_self() i stedet.

Og saa er dette en udemaerket illustrering af race conditions, det
klassiske traadprogrammeringsproblem...

Rasmus

 


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