BASIC

Author Topic: [RE-RELEASED] MultiThreading() ..includes FPS limit  (Read 7768 times)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Need to reduce FPS in the second thread, so here it is:

Just put this before your main loop:
Code: Text [Select]
   GLOBAL THREAD_FPS=60  //Second Thread Runs at 60 FPS
   StartThread_()
   LIMITFPS -1
 


Put This in your main loop:
Code: Text [Select]
print magicnumber,10,10
 



Put this after your main loop..
Code: Text [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.
« Last Edit: 2008-Oct-17 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2605
    • View Profile
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)

Offline trucidare

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1377
  • Bachelor of Fail
    • View Profile
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

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
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.

« Last Edit: 2008-Oct-17 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
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.
« Last Edit: 2009-Jan-12 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)