<p>We have two tasks (T1 and T2) in our vxWorks embedded system that have the same priority (110).<br>
How does the regular vxWorks scheduler deal with this if both tasks are ready to run?<br>
Which task executes first?</p>

[{'answer_id': 80240, 'author': 'unwieldy', 'author_id': 14963, 'author_profile': 'https://Stackoverflow.com/users/14963', 'pm_score': 4, 'selected': True, 'text': '<p>The task that will run first is the task that is spawned first as realized by the VxWorks scheduler task. VxWorks uses <strong>priority-based scheduling</strong> by default. So in your case, since T1 and T2 have the same priority, whichever one gets the CPU first will continue to run indefinitely until it is explicitly blocked (using <em>taskSuspend</em> or <em>taskDelay</em>), at which time the other READY task will execute until it is blocked, and so on. This ought to be controlled by semaphores or mutexes (mutices?)</p>\n\n<p>The main problem with priority-based scheduling is illuminated by this exact problem. How do we determine how long to let these tasks run? The fact that they have the same priority complicates things. Another concern is that VxWorks tasks that have high priority (lower number means higher priority) can preempt your application which you must be prepared for in your code. These problems can be solved by using <strong>round-robin scheduling</strong>. The additional problems posed by round-robin scheduling and the solutions are all described <a href="http://www.cs.ru.nl/lab/vxworks/vxworksOS.html" rel="noreferrer">here</a>.</p>\n'}, {'answer_id': 88820, 'author': 'Benoit', 'author_id': 10703, 'author_profile': 'https://Stackoverflow.com/users/10703', 'pm_score': 2, 'selected': False, 'text': '<p>VxWorks has 256 priority levels (0 is highest, 255 is lowest). At any given time, the highest priority task runs on the CPU. Each priority level conceptually has a queue where multiple tasks queue up for execution.</p>\n\n<p>We have 3 tasks at the same priority A, B, C.  Assume A is executing.<br>\nWhen A blocks (taskDelay, SemTake, msgQReceive), B will start execution.<br>\nWhen A unblocks, it is put at the end of the queue.  We now have B, C, A.<br>\nWhen B blocks, C takes over, etc...</p>\n\n<p>If Round Robin scheduling (Time slicing) is enabled, the same concept applies, but the task gets put at the end of the queue when its time slice is over.</p>\n\n<p>Note that a task being pre-empted by a higher priority task will NOT affect the order of the queue.  If A was running and gets pre-empted, it will continue execution when the higher priority task is done.  It does not get put at the end of the queue.</p>\n'}, {'answer_id': 879630, 'author': 'robert.berger', 'author_id': 108743, 'author_profile': 'https://Stackoverflow.com/users/108743', 'pm_score': 1, 'selected': False, 'text': '<p>By default the one which is spawned first will be executing and unless it gives up the CPU the other will never run.</p>\n\n<p>You can explicitly enable round robin, than they will timeslice.</p>\n'}]
['https://Stackoverflow.com/questions/79892', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10703/']