On 09.05.2011, at 22:03, kxng wrote:

> my test program now looks like this:
> 
> main thread:
>   initialize sharedArray[i] = -1
>   create thread from start_cb()
>   call output()
> 
> output()
> {
>   for (i..30000)
>   {
>       while(sharedArray[i] != -1) Sleep(10)
>       display sharedArray[i]
>   }
> }
> 
> worker thread:
> {
>   for (i .. 30000)
>   {
>       sharedArray[i] = xxx
>   }
> }
> 
> 
> but the running time of the worker thread takes 3 times more than running 
> without using multithreading in single core, even running it in dualcore. is 
> there a better approach? and why running on multicore does not help?

"Sleep" is always wrong. In FLTK 1.3 you can use awake which is much quicker 
unless you overuse it (don't call it too often).


update_display(void*) {
  myWidget->value(xx);
}

thread() {
  for (i=0; i<3000000; i++) {
    calculate_for_some_time();
    change_some_data();
    Fl::awake(update_display, 0);
  }
}

main() {
  start_thread()
  Fl::run();
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to