English
Source / code snippets

unechtes Multithreading over Timer

 

Jens-Arne
Reumschüssel
good evening,

i'm today with Durchsicht the XProfan-Managers of Dietmar horn on The Thread.pcu-Unit of iF punched. with this can up to four "Threads" in a XProfan-Program run, The allegedly the Hauptprogramm prozessortechnisch not load. the has naturally my curiosity geweckt - I have me demand, How to that devil's it the well made has. Multithreading goes Yes known with XProfan not. After some Time be I on The idea come, that the well over Timer runs, The windows z.B. too then aufruft, if the Hauptprogramm straight in the WaitInput stick. there's with the SetTimer-API-function namely The Possibility, a Callback-routine einzubinden. And so is it sure too, How defined Tests show. because this is naturally no real Multithreading, separate during the Abarbeitung the Timer-routines is the Hauptprogramm blockiert. one can means not really insist, that it prozessortechnisch not charged would. nevertheless weg so very interesting items, The run out can, during the Hauptprogramm on Inputs wait.

I have the interessehalber time nachgebaut:
 $H windows.ph
Declare _aProc%,_aProc2%,_hTimer%,_hTimer2%,_hTimer3%,_hT%,_hT2%,_Count%,_Count2%,_Ende%

PROC TimerProc

    'unnamedParam3&=Timer-lever, so can between whom individual Timern discern (The Parameterbezeichnung stammt of Microsoft, closer Erläuterungen there moreover in the MSDN not)
    'deference: During the Abarbeitung one TimerProc-Aufrufes runs the Hauptprogramm not further! it deals it itself even not circa real Multithreading. therefore only short Codes use.
    Parameters unnamedParam1&,unnamedParam2&,unnamedParam3&,unnamedParam4&

    If unnamedParam3&=_hTimer%

        Print "Timer 1 aufgerufen"

    ElseIf unnamedParam3&=_hTimer2%

        Print "Timer 2 aufgerufen"

    EndIf

ENDPROC'TimerProc

PROC DoSomethingFast

    Parameters unnamedParam1&,unnamedParam2&,unnamedParam3&,unnamedParam4&
    Inc _Count%
    SetText _hT2%,"Timer 3: "+@Str $(_Count%)

ENDPROC'DoSomethingFast

Cls
Print "Programmende with Escape"
Print
_hT%=@Create("TEXT",%Hwnd,"Hauptprogramm: 0",250,10,160,20)
_hT2%=@Create("TEXT",%Hwnd,"Timer 3: 0",250,35,160,20)
_aProc%=@ProcAddr("TimerProc",4)'Funktionsadresse the TimerProc detect
_aProc2%=@ProcAddr("DoSomethingFast",4)
'Timer 1 produce
'Parameter 1 & 2 must 0 his, 3 is the Wartezeit until next appeal in Millisekunden, 4 is the address the TimerProc.
'deference: The Aufrufzeit must not with of/ one previous edit the TimerProc overlap, tappt im dunkeln must means long enough chosen his, so The TimerProc to the next appeal ready becomes!
'one can naturally for different Timer different Procs use, as long as it free @ProcAddr-burst gives. then is the Überschneidungsproblem not integrally so big.
'Also could one at employment of JRPC3 speedy native Procs use, The no real Zeitproblem produce. this would too The constraint the disengaged @ProcAddr-burst eliminating.
_hTimer%=~SetTimer(0,0,1000,_aProc%)
'Waiting, so it a fühlbaren Zeitunterschied into Call the Timer gives
Sleep 300
'Timer 2 produce
_hTimer2%=~SetTimer(0,0,1000,_aProc%)
'Timer 3 produce (faster appeal)
'The temporal dissolution Windows-Timers is ca. 16ms; 10 guaranteeing therefore whom schnellstmöglichen appeal the Timers.
'But this is still very slow in the comparison To echtem Multithreading, there so maximum well 60 Aufrufe per second possible are - for many interesting items might the nevertheless suffice.
_hTimer3%=~SetTimer(0,0,10,_aProc2%)
User Messages $10'End of program
_Ende%=0

WhileNot _Ende%

    'The Timer walk independent and go Windows too during the WaitInputs called, you're means independent of the Haupteingabeschleife the Hauptprogramms.
    'During Sleep go The Timer though not worn out, the works evident Profan-Program-far.
    WaitInput 250

    If (@iskey(27) and (~GetForegroundWindow()=%HWnd)) Or (%UMessage=$10)

        _Ende%=1

    Endif

    Inc _Count2%
    SetText _hT%,"Hauptprogramm: "+@Str $(_Count2%)

EndWhile

~KillTimer(0,_hTimer%)
~KillTimer(0,_hTimer2%)
~KillTimer(0,_hTimer3%)
End

circa my These To occupy, that the Hauptprogramm by the TimerProc blockiert becomes, can simply time a long Loop (for i%,0,100000) in these install. During tappt im dunkeln worn out becomes, becomes the Hauptprogramm-counter not updated. this is with Use the Unit just as.

best Regards, Jens-Arne
 
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/10/23  
 




p.specht

if one The Threads on different Prozessorkernen one zB Quadcores running bring can, should still one performance-profit To achieve his. windows can of my WIssens suitable Programmbefehle only as "Empfehlungen" To, The thing is of all others konkurrierenden Prozessen in the system tributary. (with Vorbehalt: my Hirn is in last Time there unfortunately not very reliably)
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
07/10/23  
 




Jens-Arne
Reumschüssel
the are so no real Treads. therefore walk tappt im dunkeln always on the core, the the XProfan-Program allocated is. the XProfan-Program verzweigt sozusagen to TimerProc, if the Timer this auslöst. nevertheless find I the Real "cool", if I the once so say must. On what not over ands over again stößt, if one The ideas the middle-aged Grandseigneurs ours terrific Language durchforstet!
 
XProfan X4
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/10/23  
 




Jens-Arne
Reumschüssel
in the Contrast moreover go real Threads objectively automatically on all Kernen carryed out, if to the not artificially prevented. One example is my Apfelmännchenprogramm in the JRPC3-part this Forums. For this need one but code, the multithreadingfähig is - the goes in XProfan not without expedient, separate for needed one z.B. FreeBasic or PureBasic (you know already, fbProcs and pbProcs in JRPC3 ).
 
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/10/23  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.551 Views

Untitledvor 0 min.
Sven Bader11/22/23
ByteAttack10/27/23
Uwe ''Pascal'' Niemeier10/17/23
HofK09/07/23
More...

Themeninformationen

this Topic has 2 subscriber:

Jens-Arne Reumschüssel (3x)
p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie