Re: Threading problems

Olivier Michel <[email protected]> Thu, 25 Mar 2004 10:57:05 +0100
Newsgroups gmane.comp.cybernetics.webot.contest
Organization Cyberbotics Ltd.
Message-ID <[email protected]>
Hi,

I could reproduce this problem and tryed to fix it but it is not easy... 
Strangely enough, this problem occurs only under Window. The program 
appear to work fine under Linux... Actually under Windows the same 
OpenGL context cannot be shared among different threads, instead 
different OpenGL context should be used in each thread which cause some 
problems with initialization and cleanup which is done by the main thread...

It would be possible to create a special subclass the java Thread that 
would work with camera, but it would complicate the programming API.

Instead, I would recommand you that only the main Thread should do the 
image acquisition, i.e., camera_enable() and subsequent 
camera_get_image() while you can distribute the image processing on 
other Threads. The int array receiving the image should be global 
variable to be shared between threads. Of couse, this requires some 
basic Thread synchronization to work well.

-Olivier

Olivier Michel wrote:

>Anders Lyhagen wrote:
>
>  
>
>>Hi,
>>
>>Does anyone know why this code yields a "cannot activate openGL context"
>>error?
>>
>>    
>>
>I recently made the Webots API MT-safe, but this was not enough to fix 
>that problem. It seems that the OpenGL context is not inherited in 
>subsequent Java Threads. I will try to sort that out as it is becoming a 
>recurrent question... Thanks for the source code which is very simple 
>and shows nicely the problem.
>
>-Olivier
>
>  
>
>>import com.cyberbotics.webots.Controller;
>>public abstract class Judoka0 extends Controller {
>>   static int camera;
>>
>>   public static void reset() {
>>       camera = robot_get_device("camera");
>>   }
>>
>>   public static void main() {
>>       camera_enable(camera, 64);
>>
>>       Sensors sensors = new Sensors();
>>       sensors.setPriority(Thread.MIN_PRIORITY);
>>       sensors.start();
>>
>>       while(true)
>>           robot_step(64);
>>   }
>>
>>   static class Sensors extends Thread {
>>        public void run() {
>>           while(true) {
>>               int[] img = camera_get_image(camera);
>>               try {
>>                   thread.sleep(200);
>>               }
>>               catch(Exception e){}
>>           }
>>       }
>>   }
>>}
>>
>>Best regards,
>>Anders.L
>>    
>>


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/webots-contest/

<*> To unsubscribe from this group, send an email to:
     [email protected]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/