Hi,
I’m debugging some threading issues I’m having and realised that I don’t really understand wxCriticalSection, as I can’t see how its scope is defined. I’ve based my threading on the sample application provided, with a dynamic array of custom threads and I have no problems adding threads to the array and removing threads from it. Similarly, my threads do what they’re supposed to do when I set them running.
However, I’m getting problems when I want to interact with data local to an individual thread. My algorithm follows the following logic:
1 – Invoke the thread’s Pause() method;
2 – Close the hardware ports that the thread was using;
3 – Perform my property editing;
4 – Open the hardware ports again;
5 – Invoke the thread’s Resume() method.
My array is declared in my .hpp file, with a wxCriticalSection declared immediately below it but, apart from physical proximity, I don’t understand what binds the section to the array – can anybody elucidate, please?
Additionally, I tried introducing a wxLocker into my algorithm immediately after pausing my thread, but then seemed to get deadlocked, which doesn’t happen when I run the sample application – I’m assuming that this is because my critical section is faulty somehow. I’m a novice at multi-threading, so I’m hoping that I’m missing simple.
Best wishes.
Tim Burgess
Raised Bar Ltd
Phone: +44 (0)1827 719822
Don't forget to vote for improved access to music and music technology at
http://www.raisedbar.net/petition.htm
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+u...@googlegroups.com
or visit http://groups.google.com/group/wx-users
-- ############################## Michael Himmelreich Softwaredesign Kieserstraße 15 07749 Jena Tel.: 03641 528608 Mobil: 0175 8167674 Email: mic...@himmelweb.de
Hi,
Many thanks for this. I understand what the critical section is there to achieve, it’s its scope that I’m confused about. In your example:
protected:
int property;
wxCriticalSection criticalSection;
What tells the critical section that it’s guarding the int – is it just the fact that it follows the int’s declaration?
Also, from your comments, it would appear that I should close my ports, apply the lock, perform my changes then open my ports again once the locker has run its destructor. Is this a fair comment, please?
That’s great – many thanks for clearing that up for me.