Hey All!
Tell me how ... It is required to run 128 threads, each thread has almost the same procedure, but it's somehow reluctant to write them with pens. It seems to be very to place REPT macros k = 0
REPT 128
. . . < -- changing fragment where k occurs to be replaced by an increasing number
k=k + 1
endm
Thread procedure names ThreadProc0, ThreadProc1, ... , ThreadProc127. How to format thread procedures name using the REPT macro? ThreadProc&k ?
Hi Mikl :thup:
k=0
REPEAT 10
thread$ CATSTR <chr$("ThreadProc>, %k, <")>
% echo thread$
push eax
invoke CreateThread, 0, 0, thread$, k+100, 0, esp
pop edx
k=k+1
ENDM
The % echo thread$ is just to check whether the string is constructed correctly (it does not create code).
Instead of k+100, you can pass any other lParam to the thread.
This works fine with the Masm32 SDK (or MasmBasic). However, I found out that the Masm64 SDK invoke macro doesn't handle the chr$() macro correctly, so you need some acrobatics:
k=0
REPEAT 10
thread$ CATSTR <chr$("ThreadProc>, %k, <")>
% echo ***************** thread$
push rax
mov rax, rsp ; rcx rdx r8 r9
push rax ; arg 6
push 0 ; arg 5
mov r9, k+100 ; arg 4
mov r8, thread$ ; arg3
xor edx, edx ; arg2
xor ecx, ecx ; arg1
call CreateThread
pop rdx
pop rdx
pop rdx
k=k+1
ENDM
Demo attached.
Ciao jj2007!
Mille grazie!
Di niente, carissimo Mikl ;-)
Note that the demo attached above works, technically speaking. However, it does create ten threads in no man's land, where they certainly crash miserably. I am using x64dbg, which cannot look inside the threads. It's harmless, because ExitProcess kills them all, but still, don't expect anything useful from these threads.
Thanks everyone! (https://wasm.in/styles/smiles_s/thank_you.gif) Results can be seen in «Sleep Sort» (http://wasm.in/threads/sortirovki-s-animaciej.34674/page-5#post-436533) and in «Spaghetti sort» (http://wasm.in/threads/sortirovki-s-animaciej.34674/page-5#post-436534). Thanks again!
Quote from: Mikl__ on February 21, 2023, 11:44:08 PM
Thanks everyone! (https://wasm.in/styles/smiles_s/thank_you.gif) Results can be seen in «Sleep Sort» (http://wasm.in/threads/sortirovki-s-animaciej.34674/page-5#post-436533) and in «Spaghetti sort» (http://wasm.in/threads/sortirovki-s-animaciej.34674/page-5#post-436534). Thanks again!
Is spaghetti sort about sort out the right straw that leads to a kiss with a cute lady? :biggrin:
Hi, daydreamer!
It is Spaghetti sorting (https://wasm.in/threads/sortirovki-s-animaciej.34674/page-6#post-436561) (https://wasm.in/styles/smiles_s/mosking.gif)
«Spaghetti sorting» ― belongs to the class of "Parallel sortings". Let's represent an array of unsorted numbers as a bunch of dry spaghetti of the appropriate length. Stand the spaghetti upright on a flat surface. A press is lowered on top of the spaghetti until it meets the longest pasta. Delete this spaghetti and insert it at the end of the (initially empty) array of sorted spaghetti. Each time the press touches the next pasta, we fix the next sorted element and remove it from the array of unsorted elements. Repeat until all spaghetti are sorted. Worst, average and best time complexity O(n)
In practice, it might be a fast option to check simultaneously for the top and bottom:
.if eax>max
mov destTop, eax
inc destTop
swap max, eax
.elseif eax<min
mov destBottom, eax
inc destBottom
swap min, eax
.endif
Ciao jj!
Bubble sorting (+1) --> Shaker sorting (+2) --> Optimized Shaker Sort (+4)
Quote from: Mikl__ on February 26, 2023, 09:01:36 PM
Booble sorting --> Shaker sorting --> Optimized Shaker Sort
Something went wrong when sorting the boobles :tongue:
(https://akns-images.eonline.com/eol_images/Entire_Site/2014822/rs_600x600-140922141755-600.3boobs.cm.92214_copy.jpg?fit=around%7C1200:1200&output-quality=90&crop=1200:1200;center,top)
[delete]