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.

DarkBASIC Professional Discussion / Multi-threading in DBP

Author
Message
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 10th Jun 2011 05:55
Does anyone know if DBP is capable of multi-threading? I\'ve been wondering for a while, and now I need to know.

Thanks,
Amo.

MayoZebraHat 1979
18
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 10th Jun 2011 07:04
No. Individual Plug-ins can have separate threads open but not DBP code.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Jun 2011 09:20
Dark Physics is multi-threaded, as is Dark Lights and possibly Dark AI.

You can use the Intel developer tools to see how much multi-threading is going on. My current project has a threading value of 1.02, so something else is doing it too, maybe part of Box 2D.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jun 2011 11:03
Wasn't there a plugin in development awhile back to add multi-threading to DB projects?

MayoZebraHat 1979
18
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 10th Jun 2011 12:18
@BatVink - I'm pretty sure the core Sound/Music ones do too... like I said plugins can have threads. But DBPro as a language doesn't allow for running more than one routine.
@Phaelax
The matrix plugins have a Mutex type feature, jumping out of the middle of one function into another then back, but I'm pretty sure Ian has said it would not be very safe to try and do MT with Native DBPro routines/subs/functions/cats.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 10th Jun 2011 19:21
Ugh! It seems a little unstable from what I've just read. Even if those people got it to work for them, it sounded touchy. Maybe I'll try multiple processes instead. Actually, that would probably work better for what I am doing anyway. Here's the dealy-o:

I'm making an RPG, and I want a scripter and director controlling AI movements and actions. I was going to try to multi-thread it, but it would probably be better to just have sub-processes be called by the main exe to control said AI, as well as other things. The reason is this: I need a process which calculates easily for 1,000+ AI, and controls them, while a second process controls massive scripts for said AI, and the main process controls the actual game, player, levels, enemies etc.!

Sounds more like a multi-process thing than a multi-thread thing, right?

Thanks for the Help, guys.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 10th Jun 2011 19:56
There was a multithreading.dll somewhere, and it seemed to work fine. I can't remember where I got it though.

I think the issue was with 3D objects or other assets. You couldn't have a thread manipulating any objects while the main thread hits a sync or it would blow up on you.

However, if all the thread did was manipulate variables and then once the thread was done you use those new values in the main thread, that should be stable. Might work fine for running a script engine.

MayoZebraHat 1979
18
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 10th Jun 2011 22:57 Edited at: 10th Jun 2011 22:59
@KISTech The issue was probably caused by lack of mutual exclusion. If the main routine relies on something any extra threaded routines manipulate, best case the output is wrong, worst case you get a crash. You have to pause one routine and wait for the other one to finish. That wait time can mean no real gain in speed sometimes. But it would be useful for many things if you just put some thought into it. I would imagine the reason it's not a popular plugin or feature is no one wants to answer the tons of forum posts that will occur on "Why my multi thread not works?" I might try using one if it gets well enough but like most of my favorite plugins, it would probably end up with little to no support and no source code to pick up where they left off.

By the way, the second link was op by Torrey. Is he still around or did he move on to bigger things? He's done some excellent work for DBPro.
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 10th Jun 2011 23:40
Well, here's what I plan to do(which, I think, solves my quandary):

I have multiple process calculate for the AI, physics, player, scripting, and such(no graphics whatsoever, they're background only) and update memory addresses each cycle. The main process, on the other hand, controls the graphics, player interaction, and etc. and reads from those same addresses, then updates the screen.

I would think that splitting concurrent calculations up, would, in the long run, speed up and increase efficiency. As long as the processes aren't dependent on each other. The main process will only update a character if the position, animation, or status has changed. That way, the program doesn't snag or freeze. Basically, they would be 'conversing,' one asking another where an AI is standing, yet another asking where the player is standing, and then the culmination of these would output into a graphical world.

If the universe isn't a program, then why do planets orbit in loops, death sparks life, and human interaction is buggy and glitched?
Hockeykid
DBPro Tool Maker
18
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 10th Jun 2011 23:54
MayoZebraHat 1979
18
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 11th Jun 2011 00:16 Edited at: 11th Jun 2011 02:18
Yes, the same one that was posted above by Phaelax? The second link? LOL.

Oh, and yeah... I think plugging values into memory or a place holder then shutting down the calculating threads or pausing them would work well enough while the main thread does the updates.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jun 2011 13:05
There's so much global state in pretty much all of the DBPro plug-ins, that they just aren't safe to multithread fro DBPro. The only safe way to multithread is to do it in the plug-ins, avoid accessing other plug-ins that aren't multithread safe, but mostly to design your plug-in that way right from the beginning.

If you have a long-running task and can arrange a point where the process can be interrupted safely, then you can use the coroutine functions in my function pointer plug-in.

I have used coroutines myself to load terrain on-demand in the main loop without stalling the game. Each terrain block of 256x256 was made up of 16x16 limbs - one limb was created, textured and added to the main terrain object per frame. The only problem I had was with DBPro's frustum culling of the limbs that I added - on occasions, they were being culled when they should be in view.

Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 12th Jun 2011 19:21
Yeah. I realized that from everything I read about multi-threading DB. Thank you, Ian. I have chose to instead have parallel tasks. Should be what I need.

If the universe isn't a program, then why do planets orbit in loops, death sparks life, and human interaction is buggy and glitched?
Mistrel
Retired Moderator
20
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 12th Jun 2011 22:03
PureGDK is 100% thread safe.

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 13th Jun 2011 02:35
Quote: "Basically, they would be 'conversing,' one asking another where an AI is standing, yet another asking where the player is standing, and then the culmination of these would output into a graphical world."

That's the thing, how are you going to have these processes converse with each other and not step on each other's toes? It sounds tricky.


A 3D marble platformer using Newton physics.

Login to post a reply

Server time is: 2026-07-10 21:17:34
Your offset time is: 2026-07-10 21:17:34