cpu multi-core , dual-core

BlitzMax Forums/BlitzMax Programming/cpu multi-core , dual-core

Cronos(Posted 2007) [#1]
is possible make true dual-core or multi-core app ???


FlameDuck(Posted 2007) [#2]
No.


ziggy(Posted 2007) [#3]
If you mean multithreading on several cores, I don't think so with current version of BlitzMax. If you mean let the code execute in both threads for calculations etc, this can be done with current BlitzMax version modifing the BMK utility to activate some speciffic flags when compiling C and C++ source code, and rebuilding all the modules. But I would wait to the next BlitzMax update as it is anounced for a wekk or so, and it is suposed to have some speed improvements, so maybe this is already done 'officially' (or maybe not, who knows!)


degac(Posted 2007) [#4]
well it depends on the application...


ImaginaryHuman(Posted 2007) [#5]
For something to run on more than one core or cpu, the app has to be split up into parts. Each part is a thread. Or you could do it with multiple processes which are the same thing but are very isolated from each other. The o/s is then able to assign a thread or process to run on a core while another is running on another core. So long as the o/s supports threads and/or processes and also supports either multi-core CPU's or multiple CPU's, it should be able to schedule the threads/processes to individual cores/cpu's.

You will need your own or a third party's thread code in order to use threads in BlitzMax as it is not currently supported and you are totally on your own as to ensuring that it is `safe` to do so, there are a lot of issues to consider such as one thread changing data which another thread is assuming to be in a given state, plus issues with the garbage collector etc.

You could use the Free Process library but processes aren't as easy to use as threads. Whatever you do you'll have to do most of the work yourself.

I made my own script system and implemented my own scheduler to split up my scripts as threads as if running in multitasking, but it's really only one process with virtual threads, so it doesnt use any other cores. Would be really nice to have proper thread support.


N(Posted 2007) [#6]
Flat out no. You cannot safely use threading in BlitzMax.


Cronos(Posted 2007) [#7]
'it use dual-core ???
' blitzmax multitasking example

Strict

Global TaskManager:TTaskManager=New TTaskManager

Function task1()
Print "task1"
End Function

Function task2()
Print "task2"
End Function

TaskManager.StartTask 10,task1
TaskManager.StartTask 20,task2

Graphics 640,480

While WaitEvent()
DebugLog CurrentEvent.toString()
Wend

End

Type TTask
Field _hertz#
Field _count
Field _millis
Field _ticks
Field _callback()
Field _busy

Method Start(hz#,callback())
_count=0
_hertz=hz
_millis=MilliSecs()
_callback=callback
TaskManager._tasklist.AddFirst Self
End Method

Method Stop()
_hertz=0
TaskManager._tasklist.Remove Self
End Method

Method Update(ms)
Local count
If _busy Or _hertz=0 Return 'ignore if stopped or already in callback
_busy=True
count=((ms-_millis)*_hertz)/1000
If count>_count
_ticks:+1
_count=count
_callback()
EndIf
_busy=False
End Method

End Type

Type TTaskManager
Global _tasklist:TList
Global _timer:TTimer
Global _event:TEvent

Method New()
_tasklist=New TList
_event=CreateEvent( EVENT_TIMERTICK,Null,0 )
AddHook EmitEventHook,hook
_timer=CreateTimer(100,_event)
End Method

Function hook:Object( id,data:Object,context:Object )
Local ms
Local t:TTask
If data<>_event Return data
ms=MilliSecs()
For t=EachIn _tasklist
t.Update(ms)
Next
End Function

Method StartTask:TTask( hertz#,callback() )
Local t:TTask
t=New TTask
t.Start hertz,callback
Return t
End Method

End Type


FlameDuck(Posted 2007) [#8]
'it use dual-core ???
No.
' blitzmax multitasking example
No.


ImaginaryHuman(Posted 2007) [#9]
Where there's a will there's a way, guys, come on. Just saying no is not helpful.


FlameDuck(Posted 2007) [#10]
Where there's a will there's a way, guys, come on.
No there isn't. Short of driving over to Marks house and threatening him at gunpoint, to include this functionality in a future'ish release there is no practical way to write a multi-kernel-threaded program in BlitzMAX. BlitzMAX does not support the creation (forking) of threads, nor does BlitzMAX provide a thread synchronization mechanism (like a monitor) to resolve race situations and prevent deadlocks.

Just saying no is not helpful.
Well, helpful or not, it happens to be the truth.

If there was a reliable way to do it, it would have been done already. The only solution I've found is to make a separate program in another language that supports threads and does provide a synchronization mechanism (or write your own). However by the time you finish writing all that, and the boilerplate code that goes with it, you may as well switch to that language entirely, as there is no longer a compelling reason to use BlitzMAX.


iprice(Posted 2007) [#11]
Write 2 apps that communicate over 127.0.0.1.


ImaginaryHuman(Posted 2007) [#12]
Ethernet? Wouldn't that mean you have overhead for sending and receiving the data? Does it work on the same computer without a network?


ziggy(Posted 2007) [#13]
if you're trying to do it with 2 apps, I would recomend you to use pipes.


iprice(Posted 2007) [#14]
Pipes? Tell me more about them and how to use them with blitzmax :)


tonyg(Posted 2007) [#15]
Is this the stuff in PUB.FreeProcess?


ziggy(Posted 2007) [#16]
Yes, it is on freeprocess. Pipes are a stream to comunicate 2 apps, you can see, as instance, how the debuger works in the MaxIDE to get and send data to the hosted debuged application.