BlitzThreads Part Duex.

Community Forums/Showcase/BlitzThreads Part Duex.

AntonyWells(Posted 2005) [#1]
http://www.excess.eclipse.co.uk/dreamspace.mod.zip

Well it's the DVD repacking of Part...Un..Une...One...

Posted it about 8 months ago, or 5 months ago..depending on my ability to read a date correctly.
Would be GREEEAT if someone with a mac/linux added Calls for the mac linux.

You can use the ?mac ?linux ?x86 compiler directives to add this into the same lib.

It's a module in this form, but it's part C++, so it'll be straight forward. I just have no mac/linux set up to do it.

You'll all need this come BlitzMaxPs3...:)


AntonyWells(Posted 2005) [#2]
From the original Thread. Just checked the rar and there were no docs/source, just the mod `mam.


It's object driven, although there are function wrappers for those used to that.

Classes are(There's no docs)

TThread.

Global functions(Contained within TThread. I.e TThread.

Create() )
Create( BlitzFunction ) Create a thread and return a TThread object.
RunAll() 'Runs all threads
PauseAll() 'Pauses all threads
StopAll() 'Stops all threads

Local functions specific to each thread instance,

Run() 'Runs the function provided when creating the thread, in another thread.

Priority( Value:Int) 'Set the threads priority, value ranges from 1 to 7. (default = 3, pre-set)

Pause() 'Pause the thread

Resume() 'Resume the thread,
-
Global functions within TThread to allow async data access,
All return a TResource object/integer handle.

ProtectInt( x variable )
ProtectFloat( x variable )
ProtectBank( Bank:TBank )
ProtectStream( Stream:TStream )
-

With the tResource object returned, you can lock access rights to it within your thread,

Wrapper functions are,

ThreadHandle =CreateThread( Function )
PauseThread( ThreadHandle )
ThreadPriority( ThreadHandle,Priority )
PauseThread(Threadhandle)
ResumeThread(ThreadHandle)
StopThread(ThreadHandle)
RunThread(ThreadHandle)

There's also a manual locking system, in addition to protected storage.

Lock = CreateLock()

RequestLock(Lock)
ReleaseLock(lock)

which allows you to restrict threads of the same locking patterns to one run at a time.(Prevent deadlocks..if you're lucky :) )

TestApp

Simple mode


Update = CreateThread( UpdateVal )
NetWork = CreateThread( PrintVal )
RunThread(Update)
RunThread(NetWork)


Global ourVal

Function updateVal:Int(bb_func:Byte Ptr)

repeat
ourVal:+1
forever

End function

Function printVal:Int (bb_func:Byte Ptr)

repeat
Print "Val:"+OurVal
Delay 1000
forever

End Function

Print "Thread Handle>"+Res

repeat
Delay 5000
Print "Master thread!"
Forever



Advanced Mode



Update:TThread = TThread.Create( UpdateVal )
NetWork:TThread = TThread.Create( PrintVal )
Update.Run()
Network.Run()


Global ourVal

Function updateVal:Int(bb_func:Byte Ptr)

repeat
ourVal:+1
forever

End function

Function printVal:Int (bb_func:Byte Ptr)

repeat
Print "Val:"+OurVal
Delay 1000
forever

End Function

Print "Thread Handle>"+Res

repeat
Delay 5000
Print "Master thread!"
Forever




Install


To install, copy dreamspace.mod folder into your bmax mod folder(Windows only atm) and you're done.



Source BMX



C++ (imported by the bmx code, you don't need VC or anything.]

Call it ThreadLayer.C (Well you don't have it. You do if you want it to work but you don't have to.)



Dreamora(Posted 2005) [#3]
Max2D and input handling o not really like this module ...
unhandled memory exception error all over without any real reason *at least to me*
:-(


AntonyWells(Posted 2005) [#4]
Yeah, it's more for custom code then max's in built stuff.

Your game logic, etc. AI.. BlitzThreads(Whoever's versions.) Should be made official, and blitz made 100% thread safe. Even home pc cpus are multi-core now.


Dreamora(Posted 2005) [#5]
even if not multicore, networking singlethread is useless.

For the rest I'm using "faked" threading (using a own event system with function references etc. results in 1 Million mainloop passes at 60 FPS rendered)

But for some aspecs an own thread is needed ...
Networking is one thing, dynamic media loading another for example ...

Hopefully it will be added ... because I don't think that a next gen 3D engine can be called as such if it runs single threaded, no mather how many cores. There are things that have to run parallel ... like terrains, physics ...


Dreamora(Posted 2005) [#6]
even if not multicore, networking singlethread is quite pointless.

For the rest I'm using "faked" threading (using a own event system with function references etc. results in 1 Million mainloop passes at 60 FPS rendered)

But for some aspects an own thread is needed ...
Networking is one thing, dynamic media loading another for example ...

Hopefully it will be added ... because I don't think that a next gen 3D engine can be called as such if it runs single threaded, no mather how many cores. There are things that have to run parallel ... like terrains, physics ...