log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- Announcing the TIB 2024 Advent Calendar (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- RISCOSbits releases a new laptop solution (News:)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
- RISC OS London Show Report 2024 (News:1)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
Acorn Arcade forums: Programming: Multithreading
 
  Multithreading
  This is a long thread. Click here to view the threaded list.
 
john Message #5101, posted at 22:38, 29/5/2002, in reply to message #5100
Unregistered user Random, yes, but I presume you've all looked at Wimp2.
  ^[ Log in to reply ]
 
moss Message #5103, posted at 15:07, 30/5/2002, in reply to message #5102
Unregistered user http://www.wellytop.com/Rozilla/

Not sure how useful it is - I haven't checked what's on there.

  ^[ Log in to reply ]
 
Phlamethrower Message #5104, posted at 15:19, 30/5/2002, in reply to message #5103
Unregistered user Thanks - now I just need to find a TBAFS reader!

Wimp2 seems to be at http://www.nedprod.com/programs/RISC-OS/Wimp2/ for those who are interested...

  ^[ Log in to reply ]
 
johnstlr Message #5109, posted at 15:13, 5/6/2002, in reply to message #5108
Unregistered user Ah yes the fabled TimerMod, probably by the prolific Druck. I'd forgotten about that. It's at

http://www.armclub.org.uk/free/

Dunno how to use it, I've just downloaded it for the first time and I can't open it on this here PC.

  ^[ Log in to reply ]
 
john Message #5110, posted at 15:12, 6/6/2002, in reply to message #5109
Unregistered user Oh dear, timerMod seems no good since it can only be used by one client at a time, and can be started and stopped. I think the new one is the solution, or get that one updated?
  ^[ Log in to reply ]
 
Phlamethrower Message #5111, posted at 15:45, 6/6/2002, in reply to message #5110
Unregistered user I'll have a look at IimerMod. If I do write my own version though then chances are it'll provide functionality similar to OS_ReadMonotonicTime, OS_CallAfter/OS_CallEvery, and maybe some timers which can be stopped and started - no point writing it if it only does one thing!

I've written some of the new version of fred, and may soon be in a state to test it (albeit cooperative multithreading only).

  ^[ Log in to reply ]
 
ninj Message #5112, posted at 16:39, 6/6/2002, in reply to message #5101
Unregistered user
Random, yes, but I presume you've all looked at Wimp2.

That's preemptive multitasking, rather than multithreading though. Granted, they could be implemented in very similar ways, but preemptive multitasking also has to handle the WIMP interface (rather than just a start/stop/status interface) and it might be able to assume more stuff due to being in a task environment (though I'm not sure about that - multithreading would probably be restricted to USR mode too).

On second thoughts, I don't know enough about it. Perhaps it does do all you need and then some.

  ^[ Log in to reply ]
 
john Message #5113, posted at 15:00, 7/6/2002, in reply to message #5111
Unregistered user I don't think you should do any timers which can be stoped and started; apps can just do the subtrqacting themselves. If you let them be stopped apps start interfering with each other.
  ^[ Log in to reply ]
 
john Message #5116, posted at 14:52, 8/6/2002, in reply to message #5115
Unregistered user Wimp_ReadSysInfo 5 is what you want, I think - it gives the task handle of the current task (that wimp_poll returned to last).

Wimp_CloseDown message & service are always sent when a task which has called wimp_initialise finishes, and if a task doesn't call it, the wimp does so on its behalf, so you can rely on that. In theory a task can continue after calling wimp_closedown, just as it did before initialising, and presumably can call wimp_initialise again as a different task. Bear it in mind, perhaps?

HTH

  ^[ Log in to reply ]
 
Phlamethrower Message #5115, posted at 13:58, 15/6/2002, in reply to message #5114
Unregistered user I've got it working now, but there's a 'small' problem stopping me from releasing a copy. It has no way whatsoever of working out which program is running!

The current method uses OS_ChangeEnvironment to get the 'currently active object' pointer. However this returns &8000 for both single tasking and multitasking programs, so is useless for telling them apart.

I think I may be able to do it though:

* Use a vector to track when programs start. At this point fred will enter a 'single tasking' mode
* If a fred_init call is made, then stay in single tasking mode. Register an exit handler with OS_ChangeEnvironment so that fred knows when the task quits, at which point multitasking mode will be reentered.
* However if a WIMP_Initialise message is received, enter multitasking mode and use a WIMP call to identify the currently running program whenever fred functions are called (If there is a call to do this, that is...).
* Then, either listen out for WIMP_Shutdown messages or register an Exit handler as above to identify when the task quits - I'm not sure, but tasks may continue to run single-taskingly after calling WIMP_Shutdown, so fred must be able to cope with this.

Hopefully the above is possible, and will work...

I still haven't looked at TimerMod though unhappy

  ^[ Log in to reply ]
 
Phlamethrower Message #5114, posted at 13:58, 15/6/2002, in reply to message #5113
Unregistered user
I don't think you should do any timers which can be stoped and started; apps can just do the subtrqacting themselves. If you let them be stopped apps start interfering with each other.

Yes, that's what I was worrying about.

I've *almost* got the new version working. Everything seems OK, but there's a bug in the preemption code that locks up the computer. I think it's in some form of exit/shutdown code, but it could be anything... shock

  ^[ Log in to reply ]
 
Phlamethrower Message #5102, posted at 13:58, 15/6/2002, in reply to message #5101
Unregistered user
Random, yes, but I presume you've all looked at Wimp2.

Um, no unhappy I'll track down a copy...

Lee: I had a look at rozilla.com, but it seems to be nothing to do with programming/RISC OS/Martin Piper!

I've got fred working again now (turned out one function wasn't allocating enough memory for the thread info objects shock), and am now working on the preemptive code...

  ^[ Log in to reply ]
 
Phlamethrower Message #5117, posted at 13:58, 15/6/2002, in reply to message #5116
Unregistered user Cheers - saved me a look through the PRMs grin

Hopefully I'll have a verdict on whether it works by tomorrow...

  ^[ Log in to reply ]
 
Phlamethrower Message #5118, posted at 13:58, 15/6/2002, in reply to message #5117
Unregistered user Right, now the forums are working again (tongue)...

I've thought up a sneaky way of getting the current app. First, use OS_ChangeEnvironment to check that the current app is running at &8000. Then, use OS_FindMemMapEntries to find which page is mapped to &8000 - since RISC OS swaps pages rather than big lumps of RAM, this should be unique for each app running grin

All I need to do now is add some code to track apps which die unexpectantly, by doing two things:

1. Registering a function with atexit(), so normal exits work OK
2. Registering a function with most/all the signal handlers, so fatal errors and the like can be tracked. Unfortunately there are a ton of extra signals in UnixLib than the shared C library, so I'll have to think up some way of detecting the library in use or something. Plus signal handler functions can't be chained together, so if a Fred user uses their own handler then they'll have to make sure it calls fred_finish() if it terminates the program.

  ^[ Log in to reply ]
 
john Message #5108, posted at 13:58, 15/6/2002, in reply to message #5105
Unregistered user I'm sue someone else released a fast timer module, but maybe I'm wrong. Just anew _ReadMonotonicTime type thing would be nice smile As long as it can't be reset smile
  ^[ Log in to reply ]
 
johnstlr Message #5107, posted at 13:58, 15/6/2002, in reply to message #5105
Unregistered user

I'll also have a look at how Wimp2's 1ms timer worked, so I can implement one of those. I may release it as a seperate module since a 1ms timer could be useful in quite a few things.

Damn right it would be.


Once I've got the preemptive code working, I'll have a look at some threading systems and see what features they support, as well as have a nice release version for you people smile

POSIX threads (or pthreads) would be a class place to start as a port of the POSIX API would probably be a huge help to anyone porting from linux.

  ^[ Log in to reply ]
 
Phlamethrower Message #5106, posted at 13:58, 15/6/2002, in reply to message #5105
Unregistered user I still couldn't get it to replace the IRQ handler. A quick look in Martin Piper's pthread source revealed another method though, which is likely to be better - (temporarily) replacing the callback handler, so that you get access to the user mode regs when RISC OS is about to reenter user mode.

Multithreading now works, but a bit dodgily - if a program exits without functions registered by atexit() being called, (i.e. escape being pressed or some form of crash/error), then you'll get an abort on instruction fetch where OS_CallAfter is trying to run code which no longer exists indiff

I'll rewrite the entire thing as a module and then release a copy rather than release a semi-working copy right away.

  ^[ Log in to reply ]
 
Phlamethrower Message #5105, posted at 13:58, 15/6/2002, in reply to message #5104
Unregistered user I've almost got the preemptive code working. There's a slight problem though because C programs seem to change the base memory access to read only, so I'm unable to replace the current IRQ handler... but a couple of SWIs should be able to fix that. Might have some news on how it's working tomorrow.

I've also found (By looking at Martin Piper's pthread port) why it isn't working with the shared c library. As usual it's a case of me not reading the PRMs properly (Or Acorn not making it obvious enough wink). There are 7 reserved words at the top of each stack chunk that I was failing to copy over when creating new ones - and now I think of it I should have realised that earlier, since module code references data held there indiff

I'll also have a look at how Wimp2's 1ms timer worked, so I can implement one of those. I may release it as a seperate module since a 1ms timer could be useful in quite a few things.

Once I've got the preemptive code working, I'll have a look at some threading systems and see what features they support, as well as have a nice release version for you people smile

  ^[ Log in to reply ]
 
Phlamethrower Message #5119, posted at 13:58, 15/6/2002, in reply to message #5118
Unregistered user I'm *almost* ready for a release. It turns out that there's a mistake in the PRMs (Or the shared C library), which works to my advantage. According to the PRMs, any function registered with atexit() will only be called when the program exits normally - but that isn't the case. It turns out that atexit() functions always get called grin

Unfortunately the same isn't true with unixlib - atexit() functions do only get called when the program exits normally. At the moment I'm busy fiddling round getting the signal handlers working properly so they can trap the other occurences.

I've managed to implement some clib/unixlib detection code which works fine in GCC, even if it's a bit messy. Once the signal handlers are working properly, this code will decide whether to run the clib fred_init function or the unixlib one (Or a third one which lets you specify whether a function is registered with atexit(), and which signal handlers are registered). At the moment the signal numbers used are hard coded, but that shouldn't be a problem.

I still need to get a registered SWI base sorted out, and have a look at TimerMod though unhappy

Also, to increase the accuracy of the thread switching, each app has its own 'time till next switch' value. The value for the current app gets decreased every 'time unit' (at the moment every centisecond), so that it knows which app needs thread switching when. This is instead of using OS_CallAfter to set up a switch to occur at some point in the future, without even knowing whether that app will have been active for the full duration of that time.

  ^[ Log in to reply ]
 
john Message #5120, posted at 13:58, 15/6/2002, in reply to message #5119
Unregistered user Interesting, I am reading this still smile
I thought atexit() was always called, unless you were in a task window which was crossed off? Although, it is more useful if it's always called, but it's also very clever!
  ^[ Log in to reply ]
 
Phlamethrower Message #5121, posted at 13:58, 15/6/2002, in reply to message #5120
Unregistered user I've released V0.10 over here, the new home of Fred. At the moment it's a bit broken with respect to UnixLib, but the Shared C Library seems to work fine grin This is still what you could call a 'development' release, so don't go writing any mammoth programs with it only to find it's completely changed in the next version tongue

I've had a look at TimerMod, and I think it might be easier if I just wrote my own version instead of trying to get that one updated.

  ^[ Log in to reply ]
 
moss Message #5092, posted at 13:58, 15/6/2002, in reply to message #5091
Unregistered user This all kinda puts my coding ideas into perspective... indiff I'm small fry smile
  ^[ Log in to reply ]
 
moss Message #5084, posted at 13:58, 15/6/2002, in reply to message #5083
Unregistered user /me downloads it smile
  ^[ Log in to reply ]
 
Phlamethrower Message #5085, posted at 13:58, 15/6/2002, in reply to message #5084
Unregistered user I've got one idea on how to fix it for CLib - register each thread seperately via _clib_initialise. Whether this will work or not I've got no idea. Also it would require the threading functions to be incorporated with the CLib stubs, and possibly the compiler changing so that each thread uses its own C environment or something (Similar to how modules need a pointer to the CLib data, the threads might need pointers to the data CLib stores/provides). I don't really know until I try it though, and the amount of work needed doesn't sound too tasty at the moment unhappy
  ^[ Log in to reply ]
 
Hertzsprung Message #5086, posted at 13:58, 15/6/2002, in reply to message #5085
Unregistered user Some multithreading would be much appreciated for NetSurf development! grin
  ^[ Log in to reply ]
 
I don't have tourettes you're just a cun Message #5087, posted by [mentat] at 13:58, 15/6/2002, in reply to message #5085
[mentat]Fear is the mind-killer
Posts: 6266
I don't really know until I try it though, and the amount of work needed doesn't sound too tasty at the moment

It does look that way - maybe you should do it 'over the summer' ... wink

  ^[ Log in to reply ]
 
Phlamethrower Message #5088, posted at 13:58, 15/6/2002, in reply to message #5087
Unregistered user I've uploaded a new version (0.03) of the code... not too much has changed but the docs should now be better grin

Still no progress on the CLib front though unhappy

  ^[ Log in to reply ]
 
Phlamethrower Message #5089, posted at 13:58, 15/6/2002, in reply to message #5088
Unregistered user I think I've realised something nasty that could stop preemptive multithreading unhappy

If the thread switching was based around timed interrupts (i.e. OS_CallAfter), then the routine to do the switching wouldn't have any idea what the registers are the program is using - because RISC OS would have them somewhere at the start of its stack unhappy

Which means one of two things - pulling apart the stack (Bad idea, unless there's something in the PRMs I haven't noticed), or writing my own interrupt handler to replace the one in the hardware vector table at the base of RAM. This would look at the interrupt and if its a fred-specific one call the fred code, otherwise pass it on to the RISC OS code. I'll have a look at the PRMs to see how tricky this would be.

  ^[ Log in to reply ]
 
moss Message #5090, posted at 13:58, 15/6/2002, in reply to message #5089
Unregistered user Damn, you're good grin
  ^[ Log in to reply ]
 
Phlamethrower Message #5091, posted at 13:58, 15/6/2002, in reply to message #5090
Unregistered user I actually tried reading the PRMs once - cover to cover grin

Got bored half way through vol 1 though unhappy

The bookmark is still there though, so who knows what I might get up to this summer gringrin

Um, expect some more fred stuff tomorrow. hertzsprung has requested some more detailed info on how it works for newbie-ish assembler/C type people, so that'll be occupying me most of tonight. I'll check the PRMs for the hardware vector stuff though.

  ^[ Log in to reply ]
 
Pages (2): 1 > >|

Acorn Arcade forums: Programming: Multithreading