Best approach to stop a task -- sending it a message?

Im new to using RTOSes so Im not sure how things are generally done.. for example:

task_1 { while (1) //display and update startup screen message until told to stop

}

task_2 { while (1) //Try connecting to host.. when connected stop task1 }

How can task_2 stop the execution of task_1? Obviously task_1 cant be pending on a semaphore or mailbox message since its constanly updating the screen.

BTW, one way to do this is to combine the tasks, BUT, task_2 will always need to run, it will forever communicate with the host whereas task_1 is only there to update the video until told not to.

Reply to
Ben Nguyen
Loading thread data ...

Use a global variable of some sort to synchronize the two.

Task 1:

while (task1_run) { }

Task 2: while (1) { if (connect_to_host()) { task1_run = 0; // stop task 1 } }

Of course, instead of a global variable you could use system calls to get/set the flag.

Reply to
Gary Kato

You do not just slap in globals to communicate between tasks, unless you under stand the problems if you do it wrong.

The above example will work fine. The problem if if the variable is modified in more than 1 task. Read - modify - write operations can be the worst in preemptive systems. The task break can happen in the middle of a change. More complicated data will require a semaphore to look at the data. Or a mail box

Reply to
Neil Kurzman

Mailbox reads don't have to be blocking. Most RTOSs will let task_1 do a non-blocking read of its mailbox. If there is something there it can action it (and maybe exit); if not it can do any updating it needs to then sleep for a bit before checking again.

Reply to
Matthew Kendall

It may be worthwhile to check your RTOS manual. My guess is that it (almost certainly) describes calls to something like "StopTask()", "SuspendTask()", "BlockTask()", or a similar calls. You may also find counterpart calls like e.g. "StartTask()", "ResumeTask()", or "UnblockTask()". No need to send messages, or check semaphores...

Good luck

Waldemar

"Ben Nguyen" schreef in bericht news: snipped-for-privacy@posting.google.com...

Reply to
Waldemar

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.