Threads in blitz?

Blitz3D Forums/Blitz3D Programming/Threads in blitz?

ozak(Posted 2005) [#1]
Is there a way to run multithreaded code in Blitz or would I have to do thread stuff in a userlib? (As it would seem :)


Tiger(Posted 2005) [#2]
Edit: Sorry this works only in BlitzMax.
In Blitz3D, I don't really know if its possible.


Here is a link about this(BlitzMax):

http://www.blitzwiki.org/index.php/Threads_%28Module%29


Andy(Posted 2005) [#3]
>Is there a way to run multithreaded code in Blitz or would
>I have to do thread stuff in a userlib? (As it would
>seem :)

No, but some aspects of threading can be emulated quite sucessfully.

Andy


Techlord(Posted 2005) [#4]
Andy,

This has become a topic for me in Blitz3D lately working with GUIs and Bots. What aspects of threading can be emulated?


Ross C(Posted 2005) [#5]
I believe he means things like slowly loading in a bitmap image, say at 500 bytes per frame at a time, then creating the bitmap from within blitz.


Andy(Posted 2005) [#6]
>I believe he means things like slowly loading in a bitmap
>image, say at 500 bytes per frame at a time, then creating
>the bitmap from within blitz.

http://www.blitzbasic.com/Community/posts.php?topic=46103#513419
It's more complex than that. The image example was just a small demonstration of how to do this.

Basically you divide the code into the smallest possible components, put each component into an IF...THEN or SELECT...CASE structure and then keep a counter that is modified by the small pieces of code themselves.

If you do it right, you can simply plugin your threaded routine and make a simple call in your main loop.

EDIT: I don't use timers or any other complications in my own code. The pro is that I avoid complication and always spend the least possible time on the function. The con is that loading is slower than with a timed approach, but as you can simply prioritize what and when things are loaded, this is not really a concern.

As I always say, simple beats complex almost every time.


Andy


ozak(Posted 2005) [#7]
And this is actually how multihtreading works on a single CPU machine. Each process gets a small timeslice to execute.

Something like AI etc. which do not rely too heavy on Blitz internal stuff, would be perfect for a userlib though.


Damien Sturdy(Posted 2005) [#8]
Not in code, but isnt it possible that you multithread using a DLL? If you can't directly multithread a DLL, how about a DLL that itself spawns a thread, then directly returns to blitz, letting the thread run?


Andy(Posted 2005) [#9]
>Something like AI etc. which do not rely too heavy on
>Blitz internal stuff, would be perfect for a userlib
>though.

Why? There must be some cost(resources, speed etc.) associated with using dll's and userlibs.

Andy


ozak(Posted 2005) [#10]
The problem is that the blitz stuff runs in it's own process, so you can't run blitzcode inside the DLL. There's no cost for running the DLL's depending on how they are implemented.
It's just a bit more annoying debugging and updating them alongside your blitzapp :)


Damien Sturdy(Posted 2005) [#11]
I call for BVM to run from a DLL :P

[edit]

And BlitzScript3D, but thatd be harder for Frank to do.