Jump to content

Multithread in Isolation Mode It Possible? i think so :)


Greenseed
 Share

Recommended Posts

I know adding multithreading in autoit won't happen anytime soon and i am ok with that with experience we learn to use 2, 3 event more .exe

but how about running multiple autoit into 1 process ,

AutoitVirtualProcessSharedMemory = a array maybe all virtualprocess have access,i think autoit dev know better than me what todo here , a array of mixed value could be great , since the user can define a Global enum and easely keep track of meaning of each index

$VP_index(used to maybe to close that thread) = AutoitCreateVirtualProcess() : this function will start a new autoit thread inside the same process and execute another copy of our script , like if we run it for the first time, so no worry about not safe in multithreading

@VirtualProcessCount will be == to your thread count Created
@VirtualProcess == current running thread

if @VirtualProcess = 1 then thread1()

if @VirtualProcess = 2 then thread2()

func thread1()
    while 1
        ;mutex
        while AutoitVirtualProcessSharedMemory[$_DB_COMMAND_IN] <> ""
        wend
        AutoitVirtualProcessSharedMemory[$_DB_COMMAND_IN] = "my db command"
        If AutoitVirtualProcessSharedMemory[$_DB_COMMAND_OUT] = "for me" Then
            DoSomething()
        EndIf
    wend
endfunc

func thread2()
   if AutoitVirtualProcessSharedMemory[$_DB_COMMAND_IN] <> "" then
        Local $command = AutoitVirtualProcessSharedMemory[$_DB_COMMAND_IN]
        AutoitVirtualProcessSharedMemory[$_DB_COMMAND_IN] = "" ;delete as soon as possible to free my mutex
        
        Local $result = MySQL($command)
        ;mutex
        While AutoitVirtualProcessSharedMemory[$_DB_COMMAND_OUT] <> ""
        WEnd
        AutoitVirtualProcessSharedMemory[$_DB_COMMAND_OUT] = $result
   endif
endfunc


Func AnotherFunction()
    
EndFunc

i hope i am making sence :)

Edited by Greenseed

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
Share on other sites

another idea about the ;mutex i created , it wil be nice if you add a similar function virtualMutex($var) who will loop until var is empty without capping the cpu

i think my idea is possible with 2 .exe atm and using DLLGetStruct() to share a memory pointer for sharing data ...

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
Share on other sites

Ok i am rewriting my idea here hope my English will be better.

First of all , since this idea is not real Multi-threading , i am going to call Multi-Threading -> AutoitThreading

Autoit Dev will need to create some new function , @macro/var for this to work, atm i can think of:

;~ return the Thread ID

;~ $MyScriptToRun could work like FileInstall() and add that script as a resource inside the .exe

;~ and put copy on the hdd before exec or direct mapped to memory , Autoit Dev can answer better than me

;~ if not $MyScriptToRun then default is used and we run another instance of the SAME script we are currently running.

NewAutoitThread([$MyScriptToRun])

DelAutoitThread($thread_ID) ; will do a normal Autoit "exit" on the selected script by this thread

@AutoitThread = Thread Number , example return 1 cause this is thread 1

@AutoitThreadCount = How many thread did i make with NewAutoitThread()+1 cause we allways have at least 1 AutoitThread with our original script running

$SHARED_MEMORY[100] = this variable will be the core of that system , this is how each AutoitThread exchange data between them and this is the var we use to Activate Mutex inside a script.

;~ will loop on $SHARED_MEMORY[$index]

;~ Until var is NULL Or Empty, Call that like you want,

;~ the loop will offcourse Not take 100% cpu cycle

;~ this is far far away from a real mutex who block access To a memory region

;~ but for our need it will work good , Autoit Script dev will need To use that var correctely If they Do Not want stange problem

AutoitThreadMutex($index)

;~ Example of using $SHARED_MEMORY

Func SomeFunc($SHARED_MEMORY[0])

Local $data = $SHARED_MEMORY[0]

$SHARED_MEMORY[0] = "" ;doing this release my mutex

Do

$data

Until

EndFunc

;~ Another Example of using $SHARED_MEMORY

Func SomeFunc($SHARED_MEMORY[0])

;now i am holding my mutex until i complete here

Do

$SHARED_MEMORY[0]

Until

$SHARED_MEMORY[0] = "" ;doing this release my mutex

EndFunc

I can think of building a example using 2 .exe and sharing a pointer but i think posting this example break the LUA since i will use a shared pointer into both .exe mean i reverse engineer script for that.

And the big job Autoit Dev will have to do is not about the SharedMemory but about starting they script into each thread and a example with 2 .exe will not show anything about that.

i hope i am making more sence and i really do not think this is about mental capability but a lot about my communication skill in english.

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
Share on other sites

i did not realize this was more work (maybe i should go take a look at autoit source)... and the point was to make it simple for you to bring some kind of multithreading to autoit , so forget all about that.

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
Share on other sites

Greenseed notice how previous post doesn't have question marks.

A typo, actually. I composed the post on my iPad and didn't notice until after I submitted that I left out the question mark. I didn't feel like editing one in. Your point is still valid, though.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...