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

daydreamer

  • Member
  • *****
  • Posts: 1505
  • 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: 1577
    • 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: 1505
  • 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: 1577
    • 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: 1505
  • 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: 1505
  • 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: 1577
    • 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: 1505
  • 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: 1505
  • building nextdoor
Re: same thread proc for many threads?
« Reply #8 on: Today at 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 :)