Author Topic: same thread proc for many threads?  (Read 335 times)

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
same thread proc for many threads?
« on: February 21, 2021, 12:47:43 AM »
first I start 4 threads,1 thread=one animated object moving around
first call to random positions/direction and while loop keeping most things in registers,output to struct of data and input,and sleep some millis,exiting while loop if detect destroyed or moved far away from screen

how do I solve the get right data with lea ebx,struct+esi*size of struct,thread  #0,#1,#2,#3...to point to right struct of positions,directions,Iconhandle ...?

so if I spawn lots of threads,more than cores,I want to code it right so Sleep or other function,makes OS switch to another thread,while the thread sleeps
good idea to equate registers with variable names?

SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

TouEnMasm

  • Member
  • *****
  • Posts: 1590
    • EditMasm
Re: same thread proc for many threads?
« Reply #1 on: February 21, 2021, 04:29:25 AM »
Normal data accessing would work.
Perhaps a little code to explain the problem ?.
The Only one problem is with shared data,you don't seem to have this one ?.
https://docs.microsoft.com/en-us/windows/win32/procthread/thread-local-storage
Fa is a musical note to play with CL

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #2 on: February 22, 2021, 03:29:26 AM »
If I use same threadloop for all objects,in array of struct
In global memory
For example
Db "spider",0
Maxhp,currenthp, level
Xpos,ypos,xsize,ysize,xdelta, ydelta,angle
Iconhandle
Status,alive,dead,destroyed
Followed by example mice,cat,dog
1: starting 4 threads,how do I get it right thread output to right struct?thread0 first structure, thread 4, fourth structure?

2: wmpaint drawing objects,mouseclick messages reads data+ one thread reads the others data for test collision detection

Sorry I got stuck on this
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

TouEnMasm

  • Member
  • *****
  • Posts: 1590
    • EditMasm
Re: same thread proc for many threads?
« Reply #3 on: February 22, 2021, 05:11:29 AM »

The CreateThread  lpParameter allow to pass a parameter to the thread.
The first thhread recieve zero as parameter and the thread 4 recieve 3
.data
MyStruct MACHIN 4 dup(<>) ;MACHIN = a defined structure

Fa is a musical note to play with CL

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #4 on: February 23, 2021, 05:48:52 AM »

The CreateThread  lpParameter allow to pass a parameter to the thread.
The first thhread recieve zero as parameter and the thread 4 recieve 3
.data
MyStruct MACHIN 4 dup(<>) ;MACHIN = a defined structure
thanks
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread
so stack space in 64bit,could be how low Hutch,because I can use loads of registers instead to save values, mov to unused register?
SUSPENDED flag,seem I am possible to create many number of threads/objects I gonna use and fill structs with data and activate when needed
was thinking of first understand howto use SIMT
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #5 on: February 26, 2021, 06:56:16 AM »
I am going thru exercises,tutorials,example programs so I solved that,but missing process.h header file,but seem some could be fixed with wrappers,like with createthread -_beginthread

unsynchronized thread exercise:its all random output order,printing out 0-max number of threads,if I have a threadripper or other cpu with many cores,would OS be able to start more threads in order?
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

TouEnMasm

  • Member
  • *****
  • Posts: 1590
    • EditMasm
Re: same thread proc for many threads?
« Reply #6 on: February 26, 2021, 07:23:00 PM »

process.h is in the windows SDK all versions and translated for masm in the translated sdk http://luce.yves.pagesperso-orange.fr/header.htm
Fa is a musical note to play with CL

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #7 on: February 26, 2021, 09:26:46 PM »
thanks Yves :thumbsup:
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #8 on: March 02, 2021, 02:11:52 AM »
Normal data accessing would work.
Perhaps a little code to explain the problem ?.
The Only one problem is with shared data,you don't seem to have this one ?.
https://docs.microsoft.com/en-us/windows/win32/procthread/thread-local-storage
seem after having several proc using ,LOCAL variables,LOCAL arrays,so I should measure esp at the start of thread and max esp,so I can use optimal stack size,because max 2048 thread with standard max 1mb stack size can become too big 2048*1mb
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #9 on: March 03, 2021, 03:31:49 AM »
I am testrunning 1 main thread and 4 workerthreads and use print
loc x,y together with print inside threads doesnt work,it text appears similar randomness that output from 4 threads does
,is that whats not threadsafe runtime?
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

six_L

  • Member
  • **
  • Posts: 199
Re: same thread proc for many threads?
« Reply #10 on: March 03, 2021, 03:52:17 AM »
No codes, No facts.
are we guessing what's happen?
« Last Edit: March 03, 2021, 01:00:25 PM by six_L »
Say you, Say me, Say the codes together for ever.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8146
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: same thread proc for many threads?
« Reply #11 on: March 03, 2021, 11:06:18 AM »
 :tongue:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #12 on: March 04, 2021, 06:08:56 AM »
loc macro doesnt work with print inside threads,only main thread it works
going local variables (c-style) ,so I can take advantage of each thread has separate 1mb stack, LOCAL variable will be threadspecific
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

TouEnMasm

  • Member
  • *****
  • Posts: 1590
    • EditMasm
Re: same thread proc for many threads?
« Reply #13 on: March 04, 2021, 08:05:14 PM »

First step is to preserve the register esi edi ,startthread proc don't do that.
strange also

Quote
ret 16                            <<<<<<<<<<<<<<<<<<<<<<< ????
spawn endp

Fa is a musical note to play with CL

daydreamer

  • Member
  • *****
  • Posts: 1511
  • building nextdoor
Re: same thread proc for many threads?
« Reply #14 on: Today at 05:59:01 AM »

First step is to preserve the register esi edi ,startthread proc don't do that.
strange also

Quote
ret 16                            <<<<<<<<<<<<<<<<<<<<<<< ????
spawn endp

thanks,I fix the first
second is plan ahead
spawn proc has 4 arguments,so more control with read from readfile or som data section as alternative to randomized spawn and maybe I want to control spawns,so they trigger spawned directly when player comes close to some place/xyz coordinate
testing purposes random generator is good enough for now
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)