> Can anyone please tell me what is wrong with this code? When
> I debug it, it sometimes generate error at the line v[i] =
> 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];
>
> int *data = (int*)p;
> sprintf(msg, "%d", *data);
>
> Fl::lock();
> // 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...
>
> output_2->value(msg);
> output_2->redraw();
Widget output_2 is never initialised - you mean output_3 I think.
> Fl::unlock();
> // Release the lock...
>
> 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;
>
> for (i=0; i<100000; i++)
> {
> v[i] = 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;
> }
>
>
> static void start_cb(Fl_Button *b, void *p)
> {
> unsigned threadID;
> char msg[256];
>
> sprintf(msg, "%s", "");
>
> Fl::lock(); // Obtain a
> lock before we access the browser widget...
DO NOT lock here...
>
> output_3->value(msg);
> output_3->redraw();
>
> Fl::unlock(); // Release the lock...
>
> 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 SS14
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.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk