>
> > Can anyone please tell me what is wrong with this code? When=20
> > I debug it, it sometimes generate error at the line v[i] =3D=20
> > i; in RunProcesses().
>
> Not for me - what tools are you using? How are you testing this?
>
> For me it fails at this line in plot_cb();
>
> output_2->value(msg);
>
>
> The reason why is pretty obvious; you have never initialised output_2
> widget.
> (The output_2 widget is declared but never initialised in your code.)
>
> You probably meant output_3 widget, and if I make that change it seems
> to work OK.
>
> Further comments below:
>
>
> > volatile int v[100000];
>
> This array declared volatile as it is shared between threads.
>
>
> > void plot_cb(void *p)
> > {
> > char msg[256];
> >=20
> > int *data =3D (int*)p;
> > sprintf(msg, "%d", *data);
> >=20
> > Fl::lock(); =09
> > // Obtain a lock before we access the browser widget...
>
> NEVER call lock from this CB - it is executed in the main thread, not a
> worker thread, so the lock will be managed by fltk.
> This is described in the docs, so I am surprised that you have done
> this...
>
>
> >=20
> > output_2->value(msg);
> > output_2->redraw();
>
> Widget output_2 is never initialised - you mean output_3 I think.
>
> > Fl::unlock(); =09
> > // Release the lock...
> >=20
> > Fl::awake();
>
> NEVER call unlock() or awake() from this CB, it is in the main thread.
> See note above.
>
>
> > }
>
>
> > unsigned WINAPI RunProcesses(LPVOID lpParam)
> > {
> > int i;
> >=20
> > for (i=3D0; i<100000; i++)
> > {
> > v[i] =3D i;
> > Fl::awake(plot_cb, (void*)&v[i]);
>
> Calling awake() many times from the worker thread with no delay between
> calls is horribly inefficient.
> Do not do this, find a way to coalesce multiple updates to pass to the
> GUI at a more moderate rate, say a few hundred Hz max.
>
>
> > }
> > return (unsigned)1;
> > }
>
>
>
>
>
> >=20
> >=20
> > static void start_cb(Fl_Button *b, void *p)
> > {
> > unsigned threadID;
> > char msg[256];
> >=20
> > sprintf(msg, "%s", "");
> >=20
> > Fl::lock(); // Obtain a=20
> > lock before we access the browser widget...
>
> DO NOT lock here...
>
> >=20
> > output_3->value(msg);
> > output_3->redraw();
> >=20
> > Fl::unlock(); // Release the lock...
> >=20
> > Fl::awake();
>
> And again... These callbacks occur in the main thread, so locking is not
> necessary.
>
>
> SELEX Galileo Ltd
> Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS=
> 14 3EL
> A company registered in England & Wales. Company no. 02426132
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>
Thanks for your help. The GUI of the main thread is still not responsive. I am
finding a way to reduce the number of awake() calls as you suggested.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk