[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
 

Mystisk pthread_cond_wait fejl (muligvis en bug)



Hej Alle

Jeg her et program som skal loade et billede op i et windue og det ser sådan set perfekt ud, bortset fra at jeg skal lave en lille hack. Hack virker men det burde faktisk ikke være nødvendigt og jeg er i tvivl om det er en bug.

Mit program består (skematisk) af følgene

hovedprogram (styre/visning):
====================================== err = (pthread_mutex_init(&pic->mutex, NULL) != 0 ||
pthread_cond_init(&pic->cond, NULL) != 0);


if (!err)
pthread_mutex_lock(pic->mutex);

err = pthread_create(&thread, NULL, load_func, pic);

while(så lange der er data)
{
if (pthread_cond_wait(&pic->cond, &pic->mutex) != 0)
/* lave noget behandling */
else
fejlmelding;
}


Thread til load af billede (load_func)
===================================
void *load_func(void *arg)
{
pic = arg;
while (så længe der er noget i filen)
{
læs data;
pthread_mutex_lock(&pic->mutex);
/* læser en linie fra fil */
pthread_cond_signal(pic->cond);
pthread_mutex_unlock(pic->mutex);
} }
end


Ovenstående virker IKKE hvis hovedstyring er langsomere end load_func (hvilket den er da den snakke med X og billedet ligger i ram) pthread_cond_wait får ikke kun et fåtal af signalerne hvilket efter spec ikke skulle være tilfældet. Den skulle derimod genlåse mutex og sende load_func i låst mode. Det sker bare ikke. Hvis jeg laver en tvang med usleep(1) efter pthread_cond_signal så virker det perfekt, altså hvis loadfunc ser sådan ud:

Thread til load af billede (load_func)
===================================
void *load_func(void *arg)
{
pic = arg;
while (så længe der er noget i filen)
{
læs data;
pthread_mutex_lock(&pic->mutex);
/* læser en linie fra fil */
pthread_cond_signal(pic->cond);
usleep(1);
pthread_mutex_unlock(pic->mutex);
} }
end


Er der nogen der har en god forklaring på det her?

Hilsen Anders

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 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] *