How to implement attachThread of EventResponder?

Sam Halvoe

Member
Hello :)

I use TeensyThreads in my project and plan to use async SPI with EventResponder.
I got the idea to use attachThread of EventResponder with TeensyThreads.
But I am not sure how to implement attachThread.
Is it a weak symbol?
How should I define attachThread in my code?
(Rather a general question, I do not expect implementation details for attachThread as answer.)

Thanks in advance :)
 
You effectively can't. It needs to be a virtual function in order to be overridden by classes that inherit EventResponder but hasn't been declared correctly to allow that.
What I would do instead (and have done in the past) is inherit EventResponder and override the triggerEvent() function to do whatever you like, e.g. send a message to a thread, release a semaphore etc.
 
Okay, thanks.

But should attachThread be virtual declared then? I mean is this a "bug" in the EventResponder class?

My idea arose from this comment above attachThread:
C++:
// Attach a function to be called as its own thread.  Boards not running
// a RTOS or pre-emptive scheduler shall implement this as attach().
 
I'd call it an oversight rather than a bug, but yes - there's no way to override the default behaviour if the function isn't virtual.
 
Back
Top