VxWorks Multi-tasking function

Source: Internet
Author: User

Http://blog.chinaunix.net/uid-23741326-id-84935.html

VxWorks's task has the priority concept, its task scheduling is also based on the priority consideration, is preemptive, VxWorks's task has 256 levels, 0-255, the smaller the number indicates the higher priority. A high-priority task can break down a low-priority task and be preempted, and a low-priority task can be executed only after a high-priority task has finished executing. There are two kinds of scheduling algorithms: Full preemption and cyclic distribution. The full preemption is that, in addition to the high-priority tasks that can break down the low-priority tasks, they cannot be interrupted between tasks of the same priority, and do not execute concurrently with the priority task, but only after the task has finished executing the tasks with the same priority can be executed; Tasks of the same priority can be performed concurrently, that is, the system time slices are evenly distributed among them, so that tasks of the same priority can be executed concurrently. You can call the kerneltimeslice() function to set the scheduling method, and the parameter is the time slice that the same priority task executes.

The tasks in VxWorks have many states, as shown in the following table:

State

Describe

Ready

This task status is pending execution

PEND

This task status is blocked because some resources are unavailable

DELAY

This task status is dormant for some time

SUSPEND

This task status is pending

Break

This task state is stopped (paused), usually a breakpoint is set in the task.

A combination of various states

See the original documentation for details

To prevent the task from being mistakenly deleted, VxWorks also provides the Tasksafe () function and the taskunsafe () function, the task of calling Tasksafe () cannot be deleted, and the application is invoked elsewhere The taskdelete () function will have an error. The task can only be deleted after the task has been called Taskunsafe () . In addition, VxWorks can change the priority of a task dynamically, that is, you can call the taskpriorityset () function to modify the priority of a task during execution. For task creation, VxWorks also provides a different way for the user to call the taskspawn () function to execute it immediately after the task is created, or to call taskcreate () and taskactivate () The function divides the creation task and the execution task into two steps, that is, after calling Taskcreate () , the task is simply created and not executed, so the user can call taskactivate () when needed. To restore the execution of the task. The following is a list of VxWorks task-related functions:

Name of function

Function

Kerneltimeslice ( )

Controlling the polling scheduler

Tasklock ( )

Canceling a task rescheduling

Taskunlock ( )

Allow tasks to be re-dispatched

Taskspawn ( )

Build (Create and activate) a new task

taskcreate ( )

Creates a new task, but does not activate it.

taskactivate ( )

Activating a task that has already been created

Tasksuspend ( )

Suspend a task

Taskresume ( )

Resuming execution of a pending task

Taskrestart ( )

Restart execution of a task (i.e. from the beginning)

Taskdelay ( )

Delay task, delay unit is time slice

taskidself ( )

Gets the ID of the calling task (running)

taskidverify ( )

Verifies whether a specified task exists

Taskoptionsget ( )

Get user custom Task parameters

Taskoptionsset ( )

Set user custom task parameters

Taskidlistget ( )

Fills the task ID of all active states into a number group

Taskinfoget ( )

Get information on a task

Taskpriorityget ( )

Get the priority of a task

Taskpriorityset ( )

Change task priority

Taskregsset ( )

Set a register for a task (but cannot be used by the current task)

taskissuspended ( )

Check if a task is in the suspended state (suspended.)

Taskisready ( )

Check if a task is ready to run

Exit ( )

End running task, freeing memory *

Taskdelete ( )

End the task you set up and free up memory *

Tasksafe ()

Protect current tasks against deletion

Taskunsafe ( )

Cancels the tasksafe() operation, that is, the ability to delete the current task

Nanosleep ( )

Delay task, delay unit is time slice

Time slices

For a task, only the cyclic assignment under the same priority task has the concept of a time slice: The time slice is the time the system assigns to each task, and if a task is not completed during that time, the CPU is stripped and assigned to another task.

VxWorks Multi-tasking function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.