GLBasic forum

Codesnippets => Inline / 3rd party => Topic started by: Hemlos on 2008-Oct-17

Title: [RE-RELEASED] MultiThreading() ..includes FPS limit
Post by: Hemlos on 2008-Oct-17
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.
Title: Re: [RE-RELEASED] MultiThreading() ..includes FPS limit
Post by: bigsofty on 2008-Oct-17
Very interesting... not sure how safe this is without MUTEX locking though ;)
Title: Re: [RE-RELEASED] MultiThreading() ..includes FPS limit
Post by: trucidare on 2008-Oct-17
use HThreads is multiplatform and has mutex functions
Title: Re: [RE-RELEASED] MultiThreading() ..includes FPS limit
Post by: Hemlos on 2008-Oct-17
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.

Title: Re: [RE-RELEASED] MultiThreading() ..includes FPS limit
Post by: Hemlos on 2008-Oct-18
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.