SDK-aide/ Tools | | | | Jens-Arne Reumschüssel | here place I a method to, Multithreading with XProfan to release.
----- Info: the for this item benötigte Zusatzprogramm Profan2Cpp there here: [...] -----
Yes, XProfan is not multithreadingfähig, the is correct and remaining until further notice too so. there's but a lane, this with reinem XProfan as Programming-Language still To release. this lead over the detour, that The procedure, The as eigener asynchroner Thread launched go should, with Profan2Cpp in a C-DLL ausgelagert becomes. this becomes here in a einfachen example explains, which just in three XProfan-Text-Controls a pretended worth circa 10.000 hochzählt. eachone Counter runs in a own Thread, the itself thereafter exits and thereby over sendmessage a Return Value (here the lever of his Text-Controls) on a in the aufrufenden Program defined usermessage übermittelt.
Multithreading bid whom unschätzbaren benefit, in the "Hintergrund" releases manage to, during the Hauptprogramm weiterläuft, and thereby Handles and Speicherelemente replace to. XProfan Although multiprozessingfähig, but thereby runs the new Process in a separated Adressraum, what the return of new angelegten Handles etc. prevented. Multithreading against bid very this: a joint Adressraum of aufrufendem Program and the new Thread. but deference, this birgt too risks. For this, Please absolutely The Notes integrally under under whom code-Examples reading! These are certainly not yet entire, Ergänzungen are gladly Welcome.
both code-Examples are intense comments, so I hope, that one without further understand, what there happens.
here first of all The XProfan-procedure, The with Profan2Cpp in a C-DLL Translated go must (Please The File MultithreadingBeispielC.prf name and the begot DLL into directory the XProfan-Hauptprogramms copy, the thereafter as code-example follows):
[alternatively gibt's The finished DLL here, if someone with Profan2Cpp in the momentum not up to date is: Download]
$DLL
DLLPROC Count_C,1,"Count_C"
parameters param#
declare i&,a&,s$,hAufrufer&,ThreadRunning#,hText&,StartWert&
s$=@string $(param#,0)
'first thing the Flag for the aufrufende Program settle, that the Thread runs
a&=val(@substr$(s$,2,"²~³"))
ThreadRunning#=a&
long ThreadRunning#,0=1
'Aufrufer-Fensterhandle detect
hAufrufer&=@val(@substr$(s$,1,"²~³"))
'Textcontrol-lever detect
hText&=@val(@substr$(s$,3,"²~³"))
'Startwert detect
StartWert&=@val(@substr$(s$,4,"²~³"))
'count manage
i&=StartWert&
while i&<=StartWert&+10000
settext hText&,@st$(i&)
inc i&
endwhile
'Return Value übermitteln
@sendmessage(hAufrufer&,$1000,hText&,0)
long ThreadRunning#,0=0'Flag for the aufrufende Program for, that the Thread runs, delete
return 0
ENDPROC
now follows the normal XProfan-Program, the The three Threads, The eingangs erwähnt get, aufruft and on its end wait:
'Multithreading-example with XProfan-ThreadProc in C-DLL over Profan2Cpp
$H windows.ph
declare hDLL%,uwp&,CProcAddr&
declare hText1&,hText2&,hText3&
declare s1$,s2$,s3$
declare hThread1&,hThread2&,hThread3&
declare ThreadRunning1&,ThreadRunning2&,ThreadRunning3&
cls ~getsyscolor(4)'Mainwindow with Hintergrundgrau create (because the Text-Dialogelemente in this colour held are)
usermessages $1000'with this Message signals one Thread, that it itself now exits (the can additional with the ? Happen? ThreadRunningX& screen go, what in this example but not using becomes)
hText1&=@create("TEXT",%HWnd,"0",10,10,300,20)'here becomes Thread 1 reinschreiben
hText2&=@create("TEXT",%HWnd,"0",10,35,300,20)'here becomes Thread 2 reinschreiben
hText3&=@create("TEXT",%HWnd,"0",10,60,300,20)'here becomes Thread 3 reinschreiben
hDLL%=@usedll("MultithreadingBeispielC.dll")'in this DLL is the Thread-procedure include
'Threads started
CProcAddr&=~GetProcAddress(hDLL%,"Count_C")'"echte" ProcAddr the into DLL ausgelagerten procedure relating (with direct Profan-Procedures does it not, so Profan self not multithreading-capable is)
s1$=@st$(%HWnd)+"²~³"+@st$(@addr(ThreadRunning1&))+"²~³"+@st$(hText1&)+"²~³1"'Übergabestring for Thread 1 with the Hauptfensterhandle, the Flag ThreadRunning, the lever the Text-Dialogelements and the Startwert feed
hThread1&=~createthread(0,0,CProcAddr&,@addr(s1$),0,0)'Thread 1 started
s2$=@st$(%HWnd)+"²~³"+@st$(@addr(ThreadRunning2&))+"²~³"+@st$(hText2&)+"²~³-10000"'Übergabestring for Thread 2 with the Hauptfensterhandle, the Flag ThreadRunning, the lever the Text-Dialogelements and the Startwert feed
hThread2&=~createthread(0,0,CProcAddr&,@addr(s2$),0,0)'Thread 2 started
s3$=@st$(%HWnd)+"²~³"+@st$(@addr(ThreadRunning3&))+"²~³"+@st$(hText3&)+"²~³12345678"'Übergabestring for Thread 3 with the Hauptfensterhandle, the Flag ThreadRunning, the lever the Text-Dialogelements and the Startwert feed
hThread3&=~createthread(0,0,CProcAddr&,@addr(s3$),0,0)'Thread 3 started
'On the end the Threads Waiting and react
while (@gettext$(hText1&)<>"Fertig.") or (@gettext$(hText2&)<>"Fertig.") or (@gettext$(hText3&)<>"Fertig.")
waitinput
if %umessage=$1000'one Thread signals, that it itself now exits and commit thereby his Texthandle in &UwParam
uwp&=&UwParam
if uwp&=hText1&
settext hText1&,"Fertig."
elseif uwp&=hText2&
settext hText2&,"Fertig."
elseif uwp&=hText3&
settext hText3&,"Fertig."
endif
endif
endwhile
waitinput'so to the end with 3x "Fertig." sees
'straighten up
~closehandle(hThread1&)
~closehandle(hThread2&)
~closehandle(hThread3&)
usermessages 0
freedll hDLL%
end
Notes: · One on these point erzeugter Thread using whom Adressraum the aufrufenden Program, and so free from problems Handles ausgetauscht go can. thereby runs the Hauptprogramm moreover, during the Thread in the "Hintergrund" (=asynchron) operates. I use z.B. a such Thread, circa in a Bildanzeigeprogramm the each next Image vorzuladen and which lever on the aufrufende Program zurückzuübermitteln (through the in the example used sendmessage-method).
· one new To startenden Thread can only exakt one Parameter transfer go. it bid itself therefore on, How in the example to a String To using, in the any notwendigen Information with a possible unzweideutigen Separator separated (here "²~³") include are.
· there's a windows-API-function "GetExitCodeThread", The u.a. detect should, whether a Thread yet active is. These function functions to date (windows 10) not reliably, separate supply now and then unvorhersehbar one end the Threads back, though this yet runs. therefore is in the obigen example already the Workaround installed, the but in the example not using becomes: The Thread ought to To seinem Beginn one Flag, which address it transfer watts, on 1 settle, the the aufrufenden Program which process signals, and directly to the Thread-end ought to this Flag on 0 staid go.
· whileloop ought to in a Thread not using go. this could with further whileloops in the aufrufenden Program or simultan ongoing others Threads bump. while with Zählervariable is under C ohnehin just as quick.
· If one in the Thread externe functions aufruft, also in the aufrufenden Program (or in further Threads) at the same time using go could, must one these Kollision with a together genutzten Flag abfangen; it must then in the jeweiligen Thread/in the aufrufenden Program such a long time waited go, To The function again spare is. otherwise can it to a crash without Error Message come.
The principle the joint Use of flags ought to by the Parameter-Übergabestring in the example clear become his. always think about: it'll, differently as at Multiprozessing, one gemeinsamer Adressraum all Threads and the aufrufenden Program uses, what desired is, but too To Kollisionen lead can.
· in the aufrufenden Program already initialisierte DLLs (usedll) can in the Thread-DLL not once more initialized go (otherwise Programmabsturz). The Integration the suitable INC-File reicht.
· any with ~createthread erstellten Threads must to its termination with ~closehandle again removes go.
plenty Fun at try, and suggestions are naturally anytime Welcome! |
| 232 kB | | Bezeichnung: | BeispielC.dll | | Version: | 1.0 | | Kurzbeschreibung: | finished DLL for the Multithreading-example | | Hochgeladen: | 06/20/18 | | Downloadcounter: | | | | Download |
| | | XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM PM: jreumsc@web.de | 06/19/18 ▲ |
| |
| | p.specht
| | | | XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 06/20/18 ▲ |
| |
| | | Coole idea!
Treffenderer cover would Perhaps "Multithreading by Profan2Cpp", there Multithreading with XProfan either ex X4 by Inline-ASM-Funktionsadressen or by xpse with nProcs ( Threadbeispiele [...] [...] ) thoroughly otherwise relatively simply anzuwenden is.
cls
// 3 threads by myThread-Proc
createThread(,,procAddr(myThread,1),,,)
createThread(,,procAddr(myThread,1),,,)
createThread(,,procAddr(myThread,1),,,)
waitinput
nproc myThread
parameters data&
//...
return data&
endproc
|
| | | | |
| | | [offtopic] have the Topic into Library to SDK-aide and Tools moved. [/offtopic] |
| | | | |
| | Jens-Arne Reumschüssel | Moin,
Yes clear, the goes naturally already long with nProcs, and this is self-evident utterly the Erwähnung worth. though is one with "normalen" XProfan-Procs flexibler. In my erwähnten Grafikanzeigeprogramm functions nProcs unfortunately not, because XPSE there somewhere aussteigt (only, if one nProcs use would like, not generally). where, white I do not, because I yet no pleasure having, 16.000 Lines by degrees auszukommentieren, around the place to find, where it hakt, but that doesn't matter. fundamentally goes it Yes. With the whom Inline-ASM-Funktionsadressen is me incidentally not clear. Can so normal Procedures zugänglich make, or must The in Assembler written his?
best Regards, Jens-Arne |
| | | XProfan X3XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM PM: jreumsc@web.de | 06/23/18 ▲ |
| |
| | | momentarily müssten tappt im dunkeln still in Assembler written been his.
therefore would me one XPSE-Update irritate, that the "nProfan" in XProfan-Inline-Asm umsetzt. I could there presumably too plenty "Overhead" conserve and new Order in XPSE bring. but the row to... |
| | | | |
|
AnswerThemeninformationenthis Topic has 3 subscriber: |