Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Probably a silly Q (Threading)

Author
Message
Silicon Zombie
17
Years of Service
User Offline
Joined: 7th Oct 2007
Location: UK
Posted: 8th Oct 2007 01:56
Now you'll probably have to give me allowances. Im used to the drag and drop luxury of delphi so DB is a little bit of a culture shock!

The q is:

I have a main program loop that calls two functions.
Within these two functions I have a do..loop.

Now obviously when I run the prog it executes the first function but will never get to the second as the program is repeating the loop of function 1 forever.

Now the Q: Is is possible to run two functions (both with do..loops) at the same time..effectively multitasking.?

Probably not I expect, but maybe ive missed something.

Thanks in advance.
HeavyAmp
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 8th Oct 2007 02:58
You cant have two do loops running at the same time. There shouldn't be any reason why you need to. Just have a main do loop in your main section then keep calling the functions from there. It will mean they are constantly getting called anyway. If for some reason you need loops in your functions use For loops or While loops.

Better to be dead, than to live your life afraid.
Silicon Zombie
17
Years of Service
User Offline
Joined: 7th Oct 2007
Location: UK
Posted: 8th Oct 2007 22:59
yeah thats what I thought. I wont bore you with why I wanted to know this. Thanks for the answer.
Eevil Weevil
17
Years of Service
User Offline
Joined: 1st Aug 2007
Location: Wherever you are, I wil follow
Posted: 10th Oct 2007 19:59 Edited at: 10th Oct 2007 20:00
Yes, I wonder why you can't. Although, theoretically, you can...

First, write a program (and save it as 'writer.exe') that copies the TEMP/dpb_program and renames the copied file 'function_1.exe', or, if that's alread created, 'function_2.exe'.
Then, write your first function, and compile it. Run the writer.exe. Then write the next function, and compile it. Run the write.exe again.
now, in your main program, write:
execute file 'function_1.exe',"TEMP/",""
execute file 'function_2.exe',"TEMP",""
May put in code later. But this is just a write as you go post.

Excuse me. Yes you. Stop reading my siggy! It is private. Stoppit! Now! I'll kill you! Bleurgh! Go away or I'll format your C-drive! You are dead! I am dead! Yes! Ahem.
Jeff032
17
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 15th Oct 2007 23:03
But what would you use for communicating between the EXEs?
Using files would make it INCREDIBLY slow

Space Game WIP
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Oct 2007 23:59 Edited at: 16th Oct 2007 00:03
Currently, you'd use one or both of:
- shared memory
- localhost network connection

... as they are both available in free plug-ins.

There's also:
- Anonymous & Named pipes
- Mailslots

... neither of which are available currently, but one day I might write a plug-in for pipes.

[EDIT]
In answer to the original question, you can use the Styx plug-in for multithreading (IMO, unsafe), or you can use one of my utility plug-ins to implement co-operative multithreading, i.e. you choose when to change to another thread.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Silicon Zombie
17
Years of Service
User Offline
Joined: 7th Oct 2007
Location: UK
Posted: 16th Oct 2007 01:49 Edited at: 16th Oct 2007 01:50
Because of people kind enough to resond to my Q, I'll explain why I asked this question.

Imagine that you have a program that has a looped plasma effect (within its own function) a looped scrolling text (again within its own function) and say for arguaments sake a starfield also looped in its own function.

Now all these entities will run quite happily when called in your main loop individually. As stated above try putting them all into the main prog loop (to run at the same time) and it will only execute the first.

Now obviously the answer is simple use the one loop for all the loops in the functions, and thats the way we get round it...simple...

However, how nice would it be if we could let all these functions have their own loops and have a way they could still all be called from the main loop and run at the same time, as some of our functions may have a "do loop" whilst some have a "do while" loop....I really hope I have made this clear as I dont want the above Q to look silly!

I understand that there would be performance issues, but for simple progs it would be a really nice way of keeping code tidy (or am I wrong?)

Thanks for the responses anyway.
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 26th Oct 2007 20:50
Erm - Have you heard of subroutines?

That can simplify a loop to this:



Which keeps the loop nice and tidy, and you can put the code into distinct chunks. Good old gosubs.

Your signature has been erased by a hyper-intelligent pan-dimensional being (a mod)
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Oct 2007 02:46
Yup - you're touching on threading subjects, shared mem, even "tunneling" via pipe or tcpip - like mentioned above.

yup - you're definately thinkning out of the box and at the edges of DarkBasic - Cool!

One side note to Jeff - though not the fastest solution - a VERY portable one - I made a "Drop file" communication system - that used lowlevel OS block writes/reads - and was surprisingly fast considering it was a file. Toss that in a ram drive and you are basically at RAM speed - or close - tiny bit of "Act like a file" overhead.

Login to post a reply

Server time is: 2024-11-25 12:56:29
Your offset time is: 2024-11-25 12:56:29