![]() |
|
Multi-tasking |
essoftgui
Member #1,828
January 2002
|
I am making a GUI in DJGPP and Allegro and I want it to have multitasking capabilities. I have tried the two multitasking libraries on this site and I can't get either to compile for some reason. Are there other multitasking libraries I can try? and How would I go about writing my own? |
axilmar
Member #1,204
April 2001
|
If you are looking for multitasking for DJGPP, you won't be lucky. If you are looking for multithreading, I've made a co-operative multithreading lib some years ago that I am willing to share. [ January 12, 2002: Message edited by: achil ] |
essoftgui
Member #1,828
January 2002
|
Thanks, the multi-threading sounds interesting but I'm not totally sure what multi-threading is (I think I know but I'm not sure). What I want to do is create a GUI which runs each program as a separate task (thread?) like Linux and then switch between them with the pre-emptive (but I don't really mind if it's co-operative) method and I also need it to regularly switch from the programs running to the main GUI function to check memory, mouse position etc. and then back to the programs. |
gillius
Member #119
April 2000
|
If you want to use multiple threads, your best bet would be to switch to a modern operating system like Linux, Windows, or another UNIX rather than try to hack it into an OS that was dropped 7 years ago. If you are using Allegro then your code will be the same if you switched to Windows or Linux, assuming you have written it correctly for Allegro 4 (or the WIPs). I would suggest MingGW. You can use it from the command line exactly as you'd use DJGPP, except that it makes Windows programs rather than DOS ones. Once you get to Windows you'll want to use a threading API. I suggest finding the pthreads-win32 port of pthreads fromRed Hat. That way your program will work in Windows and Linux w/o code modification. Keep in mind that Allegro makes no guarantees about running multithreaded, so really you should only access it from a single thread at a time by using mutexes. However many parts of Allegro now use threads in the background and many parts are thread safe, but it varies based on platform and again, no guarantees on ANYTHING. Since you can't make a program based on on "maybes" you might want to reconsider your multithreaded approach unless placing all Allegro calls in a guarded section is acceptable for you. Gillius |
axilmar
Member #1,204
April 2001
|
I understand that you want to make a graphical shell for DOS, while keeping it multitasking, don't you ? That is a very interested concept and I would like to help you. Those who are saying 'don't do it because DOS is old news' forget the fun of doing-it-yourself. You do such projects in order to have fun while doing it and learn/understand a few things in a way that you wouldn't learn/understand under other circumstances. Mx-Windows has not been tested with Allegro 4.0. It works with 3.12, if I recall correctly. It is not a multitasking/multithreading lib. It is a window system, good enough for learning how to manage regions and clip output, and nothing else. The lib I was talking about was about multiple threads in the same DJGPP application by using Allegro. Most probably some change in Allegro results of a symbol not understood by MxWin, so all code below it is reported as errors by the compiler. As for DOS and multitasking, you will have to replace most functions of DOS (interrupt 0x21 mainly) with your own versions which use mutexes and semaphores to protect the critical parts of the "O/S". That means you have to dig for DOS documentation; there is plenty on the web. You will also have to implement task switching on a timer interrupt. By the way, multitasking means multiple applications running at in parallel, while multithreading means multiple paths(=threads) of execution in the same application. Threads share memory space, while applications don't(except when there is "shared memory" between apps. |
Peter Wang
Member #23
April 2000
|
I'd also suggest using some form of cooperative multitasking. For example, whenever one application is ready to give up control of the CPU, it should call a "yield" function. That function would switch the execution context to another app, which would continue from where it last yielded. You can implement this yield function using a coroutine library.
|
axilmar
Member #1,204
April 2001
|
Wow, you are the PAW author ? It was quite impressive. Does longjmp/setjmp save the whole CPU context ? I know it does under DJGPP, but I think it does not under MSVC. the "pusha" instruction can be used to store the CPU context for the main integer registers, though. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
heheh. Just tried that multitask hack in Linux. It works. Now i wonder what would happen if instead of having each thread call 'sleep' you setup a timer and had it longjmp(next,1) -- |
Peter Wang
Member #23
April 2000
|
achil, now I'm sure I know who you are :-) Yes, I wrote The Paw and IIRC we talked when you started MX-Windows. As for setjmp saving the CPU context in MSVC, I don't know. However, I think it should be okay. One thing that I think I've seen is that longjmp() might not restore local variables in the setjmp'ing function properly. Variables further up the stack seem to be okay though. Maybe it's just me... the last time I used setjmp/longjmp I was also doing somewhat dodgy things to the stack (saving and restoring [obliterating] it :-)
|
axilmar
Member #1,204
April 2001
|
Did we ? It must have been so long ago...I don't remember the slightest detail of what we talked about. Do you ? |
essoftgui
Member #1,828
January 2002
|
Thanks for all the help, I must warn you that I have not been programming in C/C++ for long (I have been programming basic for years, but only started learning C recently), only about 3 months so it looks like i'll have to learn a lot more C before I can attempt to add multi-threading to my GUI, it seems much more complicated than I thought. (or maybe i'll just go for the "shoot myself now" option!). |
essoftgui
Member #1,828
January 2002
|
Sorry, I forgot to say, I searched for "The Paw" and found this URL http://www.alphalink.com.au/~tjaden/thepaw/, if this is the same one then from the screenshot it looks brilliant, I'm downloading it now. |
Falling Sky
Member #1,823
January 2002
|
To create mutiple dimenionsal arrays use |
SamuraiCrow
Member #1,733
December 2001
|
Note: off-topic post (this question should have been a new thread) The only way I know is to make a macro that adds the missing subtractions: |
Peter Wang
Member #23
April 2000
|
achil, I'm not sure we actually talked. My email archives has this: which seems like just a generic message. I don't have my reply around. OT :-)
|
axilmar
Member #1,204
April 2001
|
Aaah yes...The ever-going quest for a unified Allegro gui...I've given up. I am going solo. |
|