[RE-RELEASED] MultiThreading() ..includes FPS limit

Previous topic - Next topic

Hemlos

Need to reduce FPS in the second thread, so here it is:

Just put this before your main loop:
Code (BEFORE MAIN LOOP...CALL ONCE) Select

   GLOBAL THREAD_FPS=60  //Second Thread Runs at 60 FPS
   StartThread_()
   LIMITFPS -1



Put This in your main loop:
Code (Main Loop) Select

print magicnumber,10,10




Put this after your main loop..
Code (MultiThread w/FPS Limit) Select

FUNCTION StartThread_:
StartThread_A()
ENDFUNCTION
INLINE
extern "C" unsigned int _beginthread(void*, unsigned int stacksize, void* args);
void ThreadFunc( void *dummy ) {StartThread_B();}
ENDINLINE
FUNCTION StartThread_A:
INLINE
_beginthread((void*)ThreadFunc, 0,NULL);
ENDINLINE
ENDFUNCTION
FUNCTION StartThread_B:
WHILE TRUE //second thread running THREAD_FPS:
magicnumber=RND(1024)
SLEEP 1000/THREAD_FPS
WEND
ENDFUNCTION


Thank you gernot for the original release, ive been intending to play with this, but i never got around to it.
It works really good, and i think i can find a thousand uses for it.
btw i ditched the sub routine, made it all functions with the same-likeness name.
Bing ChatGpt is pretty smart :O

bigsofty

Very interesting... not sure how safe this is without MUTEX locking though ;)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

trucidare

use HThreads is multiplatform and has mutex functions
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Hemlos

Quote from: trucidare on 2008-Oct-17
use HThreads is multiplatform and has mutex functions

What is mutex, and hthreads?

woops
i think this sleep command needs to be like this for fps
Quote
SLEEP 1000/THREAD_FPS

Edit: on hthreads.
I looked up hthreads....its too daunting for me to even begin to understand, and more so to implement.
I dont even have a way to test cross platform, even if i coded a c++ inline to do it.

Bing ChatGpt is pretty smart :O

Hemlos

I wanted to originally use the multithreading for mousestate to report independantly.
I think the best use for this might be networking, but i havent had time to tinker.
If anyone plays around with networking and this, let us know how well it does here..

notes:

1. maintain fps reports from each thread to find efficiency.

2. i think only 2 (main and second(this)) threads will run on windows.
Bing ChatGpt is pretty smart :O