[En-Nut-Discussion] Locking resources but not releasing...

Karol Szczepanowski karol at koszyk.org
Tue Sep 2 02:26:18 CEST 2008


Hi all,

Few days ago I have start playing with c328R camera (connected to 
ethernut by rs232)
I wanted to make a webcam. so I write CGI something like this (rest of 
code is like in httpd example)


static volatile unsigned char camera_lock = 0;
int ShowCameraImage(FILE * stream, REQUEST * req){
       unsigned char buffer_image[C328R_PACKAGE_MAX_PAYLOAD_SIZE];
       syslog(LOG_INFO, "IMG REQUEST %s %d", runningThread->td_name, 
camera_lock);
      // NutSemWait(&camera_semaphore);        do{
           syslog(LOG_INFO, "waiting %s %d", runningThread->td_name, 
camera_lock);
           NutSleep(100);
       }while(camera_lock);
       camera_lock++;
       //send headers              NutHttpSendHeaderTop(stream, req, 
200, "Ok");
       NutHttpSendHeaderBot(stream, "image/jpeg", -1);
        //camera initialization
   //copying image to stream
   //in worst case it can take about 30secs

   syslog(LOG_INFO, "JPEG file transfer complete... 
%s",runningThread->td_name);
   //NutSemPost(&camera_semaphore);
   camera_lock=0;
   return 0;


when i'm using IE and refreshing for few minutes it is working (one 
thread is returning image other are waiting) but sometimes
threads are waiting and it looks like the working thread died (semaphore 
or lock are newer released)

What am i doing wrong?

Thanks for help,
Karol




More information about the En-Nut-Discussion mailing list