Thursday, December 02, 2004

Multitasking with non-cobalt PalmOS

Multitasking is one of the oldest discussion topics-essentially, it exists in three variants: Does a Handheld OS need it, how does it work in Cobalt and how does it work in older Versions of the OS?

Here, I will discuss the third incarnation. The Palm OS documentation itself contains the following passage:

The Microkernel

Palm OS has a preemptive multitasking kernel that provides basic task management.

As we see, the Palm OS is a Multitasking OS. Now, why can't more than one App run at the same time? Applications run in a special program called UIAS. Palm licenced the original kernel used in the 68k machines from an RTOS manufacturer called Kadak or Kodak. In order to reduce the licence price, Palm agreed to keep the multitasking API hidden from third-party developers. Thus, there was no need to make the rest of the OS multitasking-capable. Only the parts that needed to multi-task(e.g. Hotsync, TCP-IP-Stack, sound streams) were coded in a special way to allow this kind of operation. This is the reason why the creation of Cobalt took that much time.

Now, that doesn't help the developer trying to create the impression of multitasking. After reading lots of documentation and discussing with others on the developer forums, I see two ways of solving the problem:

The first method is to take a look at the Palm OS sources in the resource pavillion (Hotsync,TCP/IP-Stack) and at the functions labeled system only. BTW, the only documentation about them is in the source file where they reside-there is more there than in the books. PalmSource insiders say that this method is difficult because of the badly designed code-but still possible. However, a program created this way will need thorough testing on each handheld to ensure compatibility.

The second way is officially documented by Palmsource and also widely implemented-actually, I experience it right now. This blog article was written in my Tungsten's Memo application. I switched over to Plucker to retreive the passage about the microkernel. When I returned, the memo was in the same state. I had a really comfortable feeling doing all of this, because my handheld stayed blazingly fast. Unlike the PocketPC, the application had no chance to damage any data without me noticing immediately. When every developer implements this behaviour into his program(s), the multitasking experience is perfect. The preferences allow easy storage of the data needed for such a process. The Palm OS UI Guidelines provide additional infos on the topic-look it up in the section on exiting applications.

Comment about this article, please. I am always interested in hearing developer's oppinions.

39 Comments:

Anonymous Anonymous said...

You can also implement co-operative multi-tasking using setjmp/longjmp, and GetSP/SetSP macros (to change the stack pointer).

(Oh, yeah, and I'm actually Blake Winton (http://bwinton.latte.ca/), but I don't have a blogger login, so I'm posting anonymously.)

3:32 PM  
Blogger Tam Hanna said...

Hi Blake,
first of all thanks for your comment! There is no need to register a blogger account-I thank you for personalizing your comment!
This is indeed a very interesting way of multitasking. But my knowledge of Assembler language and the 68k CPU isn't great enough to understand this solution.
I may google it when I have tike, however, my current schedule is very tight! If you have more infos, please post them here!
Best Regards
Tam Hanna

4:14 PM  
Anonymous Anonymous said...

It's Blake again... Perhaps I should sign up for a blogger id if you're going to continue writing interesting articles like this. ;)

setjmp basically saves the CPU state (including the currently executing instruction) into a structure, and longjmp sets the CPU state from a structure that you pass in. So you can call setjmp, pass the structure to other bits of your code, then call longjmp on that structure to jump back to where the setjmp call happened. If you couple that goto-like functionality with some macros to get and set the current stack pointer, you get co-operative threads.

In CodeWarrior, the macros would look like this:
#define GetSP(ptr) asm { move.l sp,ptr }
#define SetSP(ptr) asm { move.l ptr,sp }

If you google for "cooperative multitasking setjmp longjmp" you should get a few relevant hits, including the man pages at http://www.namelead.com/man/man3/setjmp.3.html Oh, and setjmp and longjmp are C functions, not Assembler. Granted, they're rarely used C functions, but they're still just C...

4:50 PM  
Blogger Tam Hanna said...

Hi Blake,
thanks for the detailled information. I haven't yet had the time to google it, as I am programming the Palm busily with my OnBoardC compiler. BTW, I am using a kind of multitasking too, but with good ole' notifcations!
I thank you for the positive feedback, maybe you could tell me how you like the other articles. I always want to improve! Feel free to mail me at any time!
Best Regards
Tam Hanna

5:03 PM  
Blogger Jonathan Hays said...

I take it based on your comments that you are talking about doing multi-tasking with notifications? You're right that it's pretty useful. I actually used it when I wrote Input Inspector (freeware). It does have limitations, though. For instance, when you get the notification, you can't access globals or access code outside of your first segment, etc. without doing chicanery. Interestingly enough, Blake (who also posted to this article) is involved with Multilink which is a tool that can help you get around some of those limitations. It's pretty cool if you can make your code work with it, though.
But back to your original topic. The other limitation is that it's cooperative multi-tasking and not pre-emptive. i.e. the OS doesn't enforce the mult-tasking. All the applications have to play by the same rules. The old Macintosh world used to play by the same cooperative multi-tasking rules, and as nice as it was in theory, there was ALWAYS one bad apple in the application bunch. I am actually more curious in looking at the source that accesses the UIAS. I didn't realize that the source for those applications was available. In fact, right after I post this to your blog, I'm going to go try and find them! Cheers!

7:11 AM  
Blogger Tam Hanna said...

Hi Jonathan,
thank you for the long and interesting comment!
I have discussed the Notification Topic yesterday with the Developer User Group. You are right, it can be annoying at times, but usually it works well-at least for me!
The Story with cooperative Multitasking is as old as Computers itself, I experienced it on a Windows 3.1 machine.... . As in real life, there is always one bad apple in the pack;-P
I may take a look at Input Inspector and Blake's Project too, altough my compiler limits me a bit-ist good ole' OnboardC. My main problem right now is: Detect a KeyDownEvent outside of App in OS 4.....
Best Regards
Tam Hanna

1:10 PM  
Blogger Jonathan Hays said...

Hi Tam,
That's actually one of the things that I do in InputInspector. You should check it out. I can send you some of my source if you want to look at it. It basically functions like the old Spy++ for Windows.

Ok, talk to you later!

-Jon

6:45 PM  
Blogger Tam Hanna said...

Hi Jon,
I have never ever used Spy++, but the InputInspector looks nice. If you could mail me the sources, I would be grateful. My program shall react to a hardware buton press.....
Best Regards and thanks for the comment
Tam Hanna

10:45 AM  
Blogger xfer said...

Hi,

I think you have a 3rd choice in simulating multitasking on PalmOS 5 : use the sound stream API. I haven't tried yet, but I think you can use it to "play" a background sound and grab a new thread on OS5.

3:37 AM  
Blogger Tam Hanna said...

The SoundStream API is a quite interesting topic, but I haven't had time to loook at it yert. From what I know, it only allows you to play a sound though, and not the running of arbitary code or a callback function!
I am not sure of this tho...

10:56 AM  
Anonymous Anonymous said...

Um, actually, the memo pad is persisting just enough state to remember what it was doing the last time it executed, then the task is going through its normal termination routines (it may save its state as part of normal termination). On start-up the memo pad is loading the state information and getting to an equivalent state.

While this operation is not the modern definition of multitasking, it is basically a process checkpointing scheme that has some interesting implications with respect to migration from one handheld to another. You could build interesting demonstration using a "memo state copy" application (have two handhelds on some network like WiFi, start editing a memo on one, stop, invoke this migrator process to copy the memo state to the other handheld, start memo on the other handheld and come up with the memo in the same state).

(I've actually done some multi-threading on OS 4 by combining some of the undocumented calls with my readings of the Kadak manuals. It always struck me as strange that they literally took away this functionality. They could have come up with their own API's since they wrote a new kernel and exported them. It's a might overcontrolling of the platform IMHO. I even had a Palm engineer spend an hour with me going over which libraries were reenterant, which where mostly reenterant, and which ones to avoid. NetLib is mostly reenterant, BTW - there's one or two API's that aren't, but you can easily get a network connection flowing. Ah, the good old days ;) )

10:47 PM  
Blogger Steven Fisher said...

There's yet another choice for multitasking, which is just structuring your task so that a single entry point can be called until completion -- in particular, on idle events or whenever you've got a few free cycles. This is the method I've used in the past for background calculations on MSDOS, Mac 68k and Windows 3.1... and it worked well enough that I never bothered to convert to real threads on Mac PowerPC or Windows NT.

It isn't always the right solution, but it shouldn't be overlooked either. It's what I plan to use in the application I'm writing right now.

2:51 PM  
Blogger Tam Hanna said...

Hi,
thanks to all for the comments. Looks like my article unearthed the discussion once again, the developer newsgroup also was full of the subject...
I think I will need to get a forum pretty soon.....
Best Regards
Tam Hanna

5:38 PM  
Anonymous Anonymous said...

Regarding the Sound-Api:
it looks like a very good choice to me! You are able to set a callback-function(SndStreamBufferCallback) - if you do something with the stream is up to you. What counts is that you continously get a function called.
Tam, which notification do you use? I bet sysNotifyIdleTimeEvent. If you do a long calculation, you don't get this notification. But you should get the sound-callback called regularly!

One Problem with the callback is, that it is limited in accessing symbols of your app. You will have to pass all via pointers.

But anyway, you should be able to do a lot with it. I never though of this. Lets wrap this API into a SysStartThread()! ;-) The docs sound like you are able to start 15 threads!

TeDe

3:44 PM  
Blogger Tam Hanna said...

Hi,
but you have to share these threads with all the other products!
Best regards
Tam Hanna

4:11 PM  
Anonymous Anonymous said...

I did a Google search on the Kadak Kernel, and the first hit I got, linked me to Kadaks home page, and said "Kadacts AMX multitasking kernel, and in the list is the first palm pilot

2:39 AM  
Anonymous Anonymous said...

Kadaks website, on the AMX kernel, had a list of commands (http://www.kadak.com/html/kdkp2520.htm) and the command for new task is cjtkcreate

4:01 PM  
Anonymous Anonymous said...

There might be another way to multitasking the Kernel, Hack Mater, X master ect. works in backround. Is there a way to streamm threds through X master?

11:49 PM  
Anonymous Anonymous said...

What about Ispin (www.taptarget.com) Ispin v2 (not released yet, is to be a guest OS and replace palm to run 68k apps. (I HOPE it runs on 68k devices)

9:00 PM  
Anonymous Anonymous said...

Or what about Multitasker?

2:37 AM  
Anonymous Anonymous said...

By the looks of it Multiasker can only run Ybasic apps on OS-5 Devices.

9:49 PM  
Anonymous Anonymous said...

Yes, it's limited to running compatible applications(it would be extremely difficult to run a conventional palm program in a multitasking environment), but it should work mostly on earlier OS, it's just that the force feedback might not work.

6:39 PM  
Anonymous Anonymous said...

If applications run in UIAS, why not rewrite it so that it can run more then 1 application? Not exacly at the same time, but have it switch rapidly what app it runs.

8:55 PM  
Anonymous Anonymous said...

##EDIT
It will be the same file name, and creator, and type as it appears in a file viewer (when booting, RAM wins)
(and if it is a System file, maybe the rewritten version can call SysTaskCreate...)

9:00 PM  
Anonymous Anonymous said...

Or CoordTask. I wanted to try it, but I could not compile it...
http://www.deepnettech.com/old/coordtask.html is the website

8:50 PM  
Anonymous Anonymous said...

I played around with UIAS by renaming Resco Explorer to UIAppShell, changing the creator to psys, and type to uish. RAM wins when booting, and the Palm OS thought Resco Explorer was UIAS.

I rebooted my Palm and when the Palm logo disappeared, instead of showing another logo it launched Resco Explorer!!!!!!! some things did not load properly like VFS

this proves that UIAS can be rewritten...

5:09 PM  
Anonymous Anonymous said...

hello, i was wondering what kind of scheduling process(scheduling algorithm) is present on Cobalt or on the other version of Palm OS?? (knowing that it uses pre-emptive multitasking, im curious of what exactly multitasking scheduling algo is operating on Palm OS) is it round robin?? hope you could help me thank you so much..

5:07 PM  
Anonymous AlphaSmart User said...

I don't know... for OS 4 you can check www.kadak.com for information on the AMX Kernel
And Cobalt used BeOS as its kernel (I think), I'm not sure how much they changed it
The OS 5 kernel/task management is undocumented, and little is known about it

Lastly this blog was moved to http://tamspalm.tamoggemon.com so you can try asking there...

12:49 AM  
Blogger products said...

China Wholesalers has been described as the world’s factory. buy products wholesaleThis phenomenom is typified by the rise ofbusiness. Incredible range of products available with China Wholesale “Low Price and High Quality” not only reaches directly to their target clients worldwide but also ensures that wholesale from china from China means margins you cannot find elsewhere and China Wholesale will skyroket your profits.china wholesale productsbuy china wholesalewholesale chinawholesale productsbuy products

4:55 AM  
Blogger products said...

We offer designer wedding dresses, custom wedding dress, cheap cell phonescheap wedding dressesbridal gowns, plus size wedding dresseswedding gowns, beautiful wedding dressesFlower Girl Dresses and so on. Buy tailor-made discount wedding dresses anddesigner wedding dresses designer lace wedding dresses to be a special brides now!

4:55 AM  
Blogger products said...

Wholesale Gemstone cheap Gemstone Jewelry from China, discount wholesale jewelry Beads, wholesale Gemstone jewelry cheapest Wholesale Naruto anime and manga cheap cosplay costumes, cheap Naruto cosplay costumes on sale, buy Naruto cosplay naruto online shop.Wholesale anime and manga naruto cosplay costumes, cheap cosplay costumes on sale, buy anime cosplay costumes online shop

4:55 AM  
Blogger Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.

4:22 AM  
Blogger Junda Xu said...

20151028 junda®
coach factory outlet
nfl jerseys
Gucci Outlet Online Sale
Abercrombie T-Shirts
hollister clothing store
ugg boots
michael kors outlet
Michael Kors Outlet Handbags Factory Price
ugg boots
toms outlet
abercrombie
mont blanc
michael kors outlet
michael kors outlet
Coach Outlet Store Online Shop
canada goose outlet
michael kors outlet
Abercrombie and Fitch Outlet Sale
Louis Vuitton Bags Outlet Store
michael kors bags
Wholesale Authentic Designer Handbags
ugg outlet store
air max 95,nike golf,nike janoski,air max 1,nike canada,nike plus,nike shox,nike factory store
michael kors handbag
Louis Vuitton Handbags For Cheap
cheap ugg boots
Christian Louis Vuitton Red Bottoms
coach outlet store online
true religion outlet
canada goose jackets

4:57 AM  
Blogger oakleyses said...

cheap oakley sunglasses, louis vuitton outlet, uggs on sale, michael kors outlet online, prada outlet, michael kors outlet online, ugg boots, oakley sunglasses, longchamp outlet, oakley sunglasses, oakley sunglasses wholesale, jordan shoes, michael kors outlet online, christian louboutin shoes, michael kors outlet, replica watches, gucci handbags, louis vuitton outlet, uggs outlet, polo outlet, nike free, chanel handbags, michael kors outlet online, christian louboutin outlet, oakley sunglasses, ugg boots, uggs outlet, kate spade outlet, nike air max, nike outlet, longchamp outlet, ray ban sunglasses, louis vuitton outlet, ray ban sunglasses, christian louboutin, longchamp outlet, michael kors outlet, louis vuitton, burberry handbags, nike air max, tiffany jewelry, burberry outlet, polo ralph lauren outlet online, tiffany and co, ray ban sunglasses

2:45 AM  
Blogger oakleyses said...

polo lacoste, burberry pas cher, true religion outlet, hollister uk, ray ban pas cher, replica handbags, ralph lauren uk, nike free uk, michael kors, true religion outlet, north face uk, nike roshe, sac longchamp pas cher, timberland pas cher, longchamp pas cher, coach outlet, mulberry uk, nike blazer pas cher, kate spade, nike air max, true religion jeans, true religion outlet, lululemon canada, nike free run, ray ban uk, nike roshe run uk, converse pas cher, guess pas cher, hollister pas cher, nike tn, michael kors pas cher, oakley pas cher, nike air max uk, nike air force, sac vanessa bruno, jordan pas cher, new balance, north face, coach purses, vans pas cher, nike air max uk, sac hermes, hogan outlet, louboutin pas cher, air max, michael kors, michael kors outlet, abercrombie and fitch uk, coach outlet store online, polo ralph lauren

2:46 AM  
Blogger oakleyses said...

iphone cases, ipad cases, iphone 6 plus cases, bottega veneta, chi flat iron, louboutin, iphone 6s cases, insanity workout, nike roshe run, babyliss, hollister, p90x workout, vans outlet, s6 case, lululemon, mac cosmetics, jimmy choo outlet, hollister clothing, nfl jerseys, north face outlet, nike huaraches, oakley, soccer jerseys, nike trainers uk, instyler, baseball bats, mcm handbags, mont blanc pens, herve leger, wedding dresses, ferragamo shoes, north face outlet, giuseppe zanotti outlet, timberland boots, ghd hair, ralph lauren, soccer shoes, iphone 5s cases, abercrombie and fitch, hermes belt, iphone 6s plus cases, valentino shoes, celine handbags, beats by dre, longchamp uk, new balance shoes, nike air max, reebok outlet, iphone 6 cases

2:48 AM  
Blogger oakleyses said...

wedding dresses, moncler outlet, pandora jewelry, toms shoes, converse, louis vuitton, ugg uk, ray ban, moncler, links of london, nike air max, marc jacobs, karen millen uk, moncler outlet, canada goose uk, canada goose outlet, ugg pas cher, juicy couture outlet, pandora jewelry, lancel, barbour, canada goose, hollister, swarovski, louis vuitton, hollister, doudoune moncler, canada goose outlet, louis vuitton, swarovski crystal, converse outlet, montre pas cher, moncler uk, coach outlet, thomas sabo, canada goose, canada goose, ugg,ugg australia,ugg italia, louis vuitton, vans, moncler, ugg, louis vuitton, barbour uk, moncler, pandora uk, replica watches, canada goose outlet, gucci, doke gabbana, pandora charms, supra shoes, moncler

2:49 AM  
Blogger 柯云 said...

2016-06-27keyun
gucci belts
christian louboutin outlet
michael kors outlet online
tory burch flats
hollister clothing store
true religion outlet
ghd hair straighteners
kate spade handbags
ray ban sunglasses uk
coach outlet online
burberry handbags
michael kors outlet online
kate spade outlet
concords 11
tory burch outlet
replica rolex watches
christian louboutin shoes
ralph lauren
beats by dr dre
vans outlet
cheap air jordans
michael kors outlet
ed hardy outlet
coach outlet
coach outlet
christian louboutin sale
michael kors outlet clearance
coach outlet online
cheap air jordans
montblanc pen
juicy couture
timberland shoes
oakley canada
montblanc pens
louis vuitton bags
nike roshe run
abercrombie outlet
louis vuitton
coach factory outlet online

8:44 AM  
Blogger Zheng junxai5 said...



zhengjx20160707
christian louboutin sale
toms wedges
christian louboutin wedges
lebron 12
nike store
true religion jeans
nike uk
louis vuitton handbags
oakley outlet
nike store uk
air jordan 8
hollister clothing
celine bags
oakley vault
michael kors handbags
longchamp handbags
coach factory outlet
nike store
cheap ray ban sunglasses
christian louboutin shoes
air max 95
cheap louis vuitton handbags
ralph lauren clearance outlet
coach factory outlet online
ralph lauren
burberry handbags
jordan shoes
timberland outlet
pandora jewelry
replica rolex watches
ghd flat iron
christian louboutin sale clearance
retro jordans 13
replica watches
kd 8
ray bans
true religion sale
michael kors outlet
ray ban sunglasses
louboutin shoes

9:51 AM  

Post a Comment

<< Home