Csound Csound-dev Csound-tekno Search About

[Cs-dev] threading problem with fltk and the api

Date2005-10-15 23:41
FromIain Duncan
Subject[Cs-dev] threading problem with fltk and the api
Attachmentscs_simple_4.cpp  cs_simple_3.csd  csound_data.h  fl_display.cpp  fl_display.h  
I remember people talking about fltk and thread problems, wondering if 
that is what I have hit.

I'm working on my 4th example, and I have a member function of an fltk 
class that get called periodically by the fltk timer callback. It then 
tries to lock the mutex for the csound data, and as soon as it does, 
csound segfaults. I can't see how this is any different from the same 
thing I did with the console thread, which worked fine. In both cases 
they used a local pointer to my main csound data structure which 
includes a mutex, and they use this local pointer to lock the mutex 
before reading table data.

Any hints? Could it be a problem with the csound api thread functions? 
If it would be useful as a test I can redo it with raw pthread functions 
and see what happens then.

Thanks
Iain

Date2005-10-16 10:22
FromIstvan Varga
SubjectRe: [Cs-dev] threading problem with fltk and the api
Iain Duncan wrote:

> tries to lock the mutex for the csound data, and as soon as it does, 
> csound segfaults. I can't see how this is any different from the same 
> thing I did with the console thread, which worked fine. In both cases 
> they used a local pointer to my main csound data structure which 
> includes a mutex, and they use this local pointer to lock the mutex 
> before reading table data.
> ...
> 	ControlWindow *cntrl_win = new ControlWindow( 400,400, "Control Window", v_cs_data );
> 
> 	//void *v_cntl_win = (void *)cntrl_win;
> 	void *v_cntl_win = NULL;
> 
> 	// can we call the add timeout function here and pass it a pointer to our display window?
> 	Fl::add_timeout(1.0, cb_timer, v_cntl_win );
> 	//Fl::add_timeout(.001, cb_timer );

The main problem is here: a NULL pointer is passed to cb_timer(), and then
as the 'this' pointer to ControlWindow::update_display() later. Removing
v_cntl_win and passing cntrl_win instead fixes the crash. I did run into
a number of minor compile errors and warnings but those are not related
to this issue.


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-10-16 19:12
FromIain Duncan
SubjectRe: [Cs-dev] threading problem with fltk and the api
>>     //void *v_cntl_win = (void *)cntrl_win;
>>     void *v_cntl_win = NULL;
>>
>>     // can we call the add timeout function here and pass it a pointer 
>> to our display window?
>>     Fl::add_timeout(1.0, cb_timer, v_cntl_win );
>>     //Fl::add_timeout(.001, cb_timer );
> 
> 
> The main problem is here: a NULL pointer is passed to cb_timer(), and then
> as the 'this' pointer to ControlWindow::update_display() later. Removing
> v_cntl_win and passing cntrl_win instead fixes the crash. I did run into
> a number of minor compile errors and warnings but those are not related
> to this issue.

Thanks again Istvan. I was struggling to get that callback timer 
working, and I guess I lost track of what tests I'd completed.

As to the concept, what do you think of that? Having the fltk window 
live in a seperate thread that redraws itself after checking on api 
values once every while.

Iain


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net