I need to have some kind of multithreaded structure in a program I’m developing, but I stumble across the continual hitch of not being able to restart a costate (thread), declared as “always on”, from its beginning, once it has been sent to sleep with a pause() and got awaken with a CoReset().
When this occurs, the program flow simply goes on in the next instruction after the pause(). It seems as though CoReset() only wakes the thread up, but is no responsible for moving the program pointer to the first line in the CoState().
I was wondering if something similar to an abort() / kill() instruction exists, but from the outside of the thread, so as to invoke it and get access to the starting point of the CoState with, let’s say, a CoBegin().
The Dynamic C release I am working with is 9.62.
Any suggestion, tutorial or further documentation will be highly appreciated.
Don’t use pause() & CoReset(). costate bodies normally run as endless loops; try using your own while yield loop. Finite state machines (i.e. switch / case statements) are easy mechanisms to use allowing downstream conditions to reset you back to square one without resorting to unstructured “jumps”.
Thank you very much for your response.
In principle, invoking a CoBegin() the objective of jumping to the first line of a thread seem to have been achieved, with loopinit() and loophead() functions helping to move the program pointer on hand.
You mention making use of own yield loops (I suppose something similar to a
, am I right?), so as to give birth to state machines, which is a good idea indeed, but taking into consideration what I have said before -some kind of movement of the program pointer under control-, which would be the
main benefits and drawbacks of the approach based on finite state machines in the face of the threaded scheme?
Don’t put parentheses after the yield. Below is a code snipit from an actual program :
wfd n = cof_serBread(buf, 254, MSSG_TMOUT); // yields until ends
flag = 1;
n = modbus_respond(n);
if (n > 0)
qc = PADRShadow | 0x80;
WrPortI(PADR, &PADRShadow, qc); // (RS485 TX mode)
dropit = 1;
wfd cof_serBwrite(resp, n);
flag = 0;
My apologies for the formatting.
Thank you for your comments.
There have been of great help to me.