|
Post by Si J on Aug 13, 2006 1:53:09 GMT
Hi, Not sure if i'm describing a sub-routine however can anyone tell me if it's possible in QB to have qb source code running in a loop at the same time there is other code being exceuted. <br> I had hoped it might be possible to have a sub-routine 'running' in a loop collecting data from either memory or a file constantly while other code presented an input method which would be able to 'pass on' the input the where the underlying 'loop' is able to gather the data from the input method and act upon it as it is programmed to do. <br> Apologies if this is hard to understand question. <br> However if this is possible, do you know if, how many can be running at once? <br> <hr> <br> ;D Simon
|
|
|
Post by earlofqb on Aug 13, 2006 19:35:28 GMT
I'm not sure if I understand your question properly, but I'll give it a go.
I think you're talking about multi-threaded applications. In such an application, while one procedure is running, another can run as well. Provided neither procedure interacts with the other's data, multi-threaded applications are a very good thing (although you need a multi-thread capable processor to run them).
An alternate way of accomplishing the same thing, is to quickly switch between procedures while one runs. This will give the illusion of a multi-threaded application. To my knowledge, it is the only way QB would be able to do so (because it's incapable of multi-threading). Of course, to do this would require quite a bit of memory and processing power (which would make it largely a waste of time, unless absolutely necessary).
Hopefully I provided some insight, for I had great difficulty understanding your question.
|
|
|
Post by Ildûrest on Aug 14, 2006 0:17:48 GMT
No, that's THE way of accomplishing multi-threading. Normally the operating system is relied upon to do this, but since DOS did not provide very much multi-tasking support, you have the difficult job of doing it yourself in QBasic. Difficult because, unless you're a programming genius and can actually make two machine language procedures run at once through some kind of interrupts system, you have to design your program so as to be able to switch between different bits and then continue where it left off.
Actually, this is usually fairly easy once you're familiar with it.
Again, no, what you need is a multi-thread capable operating system. As far as I'm aware, even the 8086 (a 16-bit processor) was capable of multi-threading. Certainly it was capable of multi-tasking as there was a UNIX release for it called Xenix.
And there's nothing wrong with processes interacting with each other's data as long as you have a method of ensuring this happens in a controlled fashion (e.g. with mutexes)
Now, in Si J's case: Not a subroutine. Subroutines are run in-line.
I'm a bit confused by what you mean by 'input method'. If you mean something like using INPUT to get information from the keyboard, then the solution is to use INKEY$. This function returns which key (if any) is being pressed RIGHT NOW**. This lets you take action if the user IS trying to type something, and if not you can get back to whate'er your 'underlying loop' is doing. So you'd just check it occasionally in your 'underlying loop'.
**Not quite, there's a combination of input buffer and repeat delay, which I can explain further if it's what you need, but the important thing is that INKEY$ doesn't WAIT for anything.
Although it depends on what you're actually trying to do, usually it isn't difficult to adapt a program to "do two things at once". The important thing is that you need to get at least one thing into a "small step" format; i.e. it does a small step and then lets you go and do something else, then next time it does another small step, resuming from where it was before. Although I'm not very sure about what you're trying to do, it sounds like this will be easy in your particular case. If you'd like more help then please provide us with more details and preferably some source code.
|
|