Pages: 1
Author Topic: Multiple Theads, are they a possibillity?  (41,290 Views)
Offline (Unknown gender) MrGriggs

Member
Joined: Dec 2010
Posts: 128
View profile
Posted on: January 27, 2011, 02:12:38 PM
I don't know if there's any point discussing this, if it's even considered.

I know not of the validity in my statement but I propose that it would give advantage to ENIGMA if it used a single thread for each process, such as the Draw process being on a seperate thread, the sound process, and step process.

Collision process maybe? I know there's many things that could be assigned to different threads, but i'd like it as follows.

Step

Draw

Sound

Collisions
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #1 Posted on: January 27, 2011, 02:46:17 PM
I believe sound(OpenAL) is already in a separated thread.

Multithreading would break compatibility with GM, although some kind of limited multithreading support might be possible in the physics subsystem(hspeed, vspeed, gravity, friction and collisions).

Multithreading the draw event might be problematic, even if no sane person would make the Draw event change variables like position, etc.
Offline (Unknown gender) MrGriggs

Member
Joined: Dec 2010
Posts: 128
View profile
Reply #2 Posted on: January 27, 2011, 03:22:36 PM
It wouldn't break compatabillity as multi threading is not addressed until the information is parsed to ENIGMA, the .Gmk or whatever, would remain the same, the user has no access to defining threads, just an .exe compiled with ENIGMA uses pre-defined threads as determined in the engine.
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #3 Posted on: January 27, 2011, 05:31:51 PM
Let me put it this way.
Say 2 instances access each other x and y.

var tmp = other_inst.x;
other_inst.x = self.x;
self.x = tmp;

In GM, this means the two x are swapped. Since the code is executed twice(2 instances), this code effectively does nothing in GM.
Now, consider a perfect parallel synchronized execution.
inst1.x = 5;
inst2.x = 10;
Now, each instance reads the x of the other to its own local tmp variable.
Now, each instance changes the position of the other. Right now, we have inst1.x = 10; inst2.x = 5;
Now, they are going to set their own x from the tmp variable. So we now have inst1.x = 10; inst2.x = 5; again.

So the end results are different. Therefore, compatibility with GM is broken.
Offline (Unknown gender) IsmAvatar

LateralGM Developer
LGM Developer
Joined: Apr 2008
Posts: 877
View profile
Reply #4 Posted on: January 27, 2011, 05:58:18 PM
Not to mention, different behaviors each run if they aren't in perfect parallel sync.
Offline (Unknown gender) Rusky

Resident Troll
Joined: Feb 2008
Posts: 954
View profile WWW
Reply #5 Posted on: January 27, 2011, 07:50:29 PM
GM compatibility (and programmer sanity) requires serialized instances rather than parallelizing them, but it would be possible to put some things in separate threads. Sound, networking, etc. could have utility threads to let game logic use it when it's ready. Drawing could be separated but it would be complicated and its usefulness would be debatable.

GPU-style parallelization could probably work with some things as well, but then again hardware accelerated graphics are the biggest candidate for that and are already implemented. CUDA/OpenCL/DirectCompute would be cool for particle systems, but those are rather out of the way and people can use them directly through C++.
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #6 Posted on: January 28, 2011, 05:48:07 AM
What I was thinking about doing is adding threading by the same mechanism that I can add instance deactivation. Basically, I would keep a new tree and shit for each thread (deactivated instances get placed in thread -1, which is never processed).

Threading an object would be as simple as saying instance_thread(inst,thread).
Users would be allowed to figure out for themselves that sometimes life isn't as easy as putting everything in its own thread and hoping depth and shit stay in order.
Offline (Unknown gender) MrGriggs

Member
Joined: Dec 2010
Posts: 128
View profile
Reply #7 Posted on: January 28, 2011, 10:05:32 AM
I understand how a thread functions, and the inconsistencies it may cause when used with particular methods.

But if things such as sound/particles and the like where to be put into seperate threads it wouldn't matter if there was a slight deviation from the norm.
Pages: 1