Hi all,
Another question regarding the threaded design (in follow-up to my earlier posts re: disis_wiimote object. When redesigning the threaded version, what I found out is something rather odd.
Basically, I have two threads (see my previous email from a couple days ago for the source files). One is the main thread where all PD-related stuff happens and another thread that deals with offending calls to wiimote (by offending I mean they cause dropped samples in the audio thread).
The two threads do not write into each other's variable pool but rather second thread compares its internal variables to the ones from the main thread to figure out what needs to be done, plus usleeps in the interim.
Everything works fine and in the destructor, I set the flag for the second thread to exit the while loop and reach pthread_exit(NULL); call. Then I do pthread_join() call in the destructor of the main thread to allow time for the second thread to close and that is the end of the destructor. To the best of my knowledge this should just work. However in practice I found out that after several connects/disconnects, the wiimote would connect but not broadcast any data (or at least the external would not perceive any). This was not the case with the non-threaded version so something must be amiss in the current threaded implementation.
What perplexes me is if I add half-second usleep after pthread_join in the *main* thread's destructor, this problem goes away making external rock solid (same seemed to help in an earlier implementation that had more than 2 threads), almost as if Pd does not want to wait for objects whose destructors so it makes them close prematurely. Yet, usleep seems to fix it despite the fact that the pthread_join should wait for the completion/exit of the other thread.
Any ideas?
Ivica Ico Bukvic, D.M.A. Composition, Music Technology Director, DISIS Interactive Sound & Intermedia Studio Assistant Co-Director, CCTAD CHCI, CS, and Art (by courtesy) Virginia Tech Dept. of Music - 0240 Blacksburg, VA 24061 (540) 231-6139 (540) 231-5034 (fax) ico@vt.edu http://www.music.vt.edu/faculty/bukvic/