Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > emulating context-switch

Reply
Thread Tools

emulating context-switch

 
 
refigh
Guest
Posts: n/a
 
      08-10-2011
hi every body,
I have a embedded board with a processor without OS on it. there are
some independent tasks which should be run always. I put them into a
while(true) loop and call them one after another i.g.

while(true){
task(1);
task(2);
task(3);
}

by above code it seems they are run concurrently.

sometimes one of these task takes too much time and then causes
problem for other tasks. I want to emulate context switch in c++. the
method I consider to implement is:
I divide each task to some reasonable parts and after reach any of
these checkpoints, a task should return and a task_manager in body of
main function select another task to continue( for example by a
priority mechanism ).
but I think pausing a function is not easy? am I right? I think I must
define many variables as static and also save the inputs of function
for call a paused function again,
is there a simpler method in assembly? does anybody has a better
suggestion?
( I should mention that it is not possible to use interrupts for me
also. )
thanks.



 
Reply With Quote
 
 
 
 
Bo Lorentsen
Guest
Posts: n/a
 
      08-10-2011
On 08/10/2011 02:31 PM, refigh wrote:

> I divide each task to some reasonable parts and after reach any of
> these checkpoints, a task should return and a task_manager in body of
> main function select another task to continue( for example by a
> priority mechanism ).
> but I think pausing a function is not easy?

No, you need to use something like async IO and longjmp to manage this,
and you need to manage an individual stack for each task, in order to
make all local values work.

And yes this is an cooperative model, and one task that does hand in a
long running loop will stop all other tasks while looping (thats why we
used "yield()" in win16

> am I right? I think I must
> define many variables as static and also save the inputs of function
> for call a paused function again,
> is there a simpler method in assembly?

The local value problem are fixed by setting up a stack per thread, and
this goes for function arguments too, as these are all stack based i C
and C++.

> does anybody has a better
> suggestion?
> ( I should mention that it is not possible to use interrupts for me
> also. )

This would be the best way to task switch, by giving time slices to each
task (using an interrupt for this), but .... depending on the platform
you are writing for/on, it may be more sensible to use your energy on
porting a custom Linux kernel to the platform, instead of reinventing
the wheel.

Else take a look at http://en.wikipedia.org/wiki/List_of_operating_systems

Lastly, I am not sure this it the prober news group for this kind of
question (nor answer)

/BL
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emulating Referrer URL? =?Utf-8?B?QmVuIEZpZGdl?= ASP .Net 4 12-15-2005 10:44 AM
Emulating referrers? Ben Fidge ASP .Net 1 12-14-2005 07:06 PM
Emulating referrers? Ben Fidge ASP .Net 0 12-14-2005 04:30 PM
Emulating variables static to the page Mike Orb ASP .Net 2 09-02-2005 03:24 PM
Emulating floating point gthorpe@ee.ryerson.ca VHDL 3 09-01-2005 09:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57