Jump to content

Multithreading Redux


xroot
 Share

Recommended Posts

What I have learned about Multihreading is the following:

All processes have at least one thread of execution, which is called the main thread. The main

thread is created when your program begins. In a multithreaded program, the main thread creates

one or more child threads. Thus, each multithreaded process starts with one thread of execution

and then creates one or more additional threads. In each thread represents a single logical unit

of work or activity.

This Multithreading allows the threads to exist within the context of a single process.

These threads share the main process, resources and are able to execute independently.

All the threads can run at the same time without interfering with each other.

A multithreaded process with two or more threads executing in time clearly showing that the threads

execute separately and execute mutually exclusively in time is multithreading.

My script shows the above criteria to be true. I finally know that Autoit3 can multithread. :)

mutiThreads.zip

Link to comment
Share on other sites

  • Moderators

SetTimer API is not multi-threading. It shares resources from the calling thread.

To test it, run a simple While/Wend loop that does some kind of counting, then do a SetTimer API call before that loop that also has a loop that counts.

You will find that you have many less cycles in your main loop when using SetTimer than you would not using it.

Now don't get me wrong, I use SetTimer all the time, it does have its place... but I only use it when my scripts/loops are not speed sensitive.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

All the threads can run at the same time without interfering with each other.

A multithreaded process with two or more threads executing in time clearly showing that the threads

execute separately and execute mutually exclusively in time is multithreading.

That is not entirely true, because in a way they do. When you only have one CPU, each thread is given a certain amount of time (or instructions) to execute. After that thread is done being executed, the next thread gets a turn, and so on. The only reason this works is because just before the next thread is given a chance to execute, the OS has to save the state of the current thread (most of the registers). When that thread gets a chance to execute again, the state is restored. The same is true for multiple cores (and multiple CPUs). The only difference is, you'll have multiple processors doing what I just described above (roughly). And, if you are using a multithreaded operating system (like Windows or Linux), then this is happening every single microsecond (even less) - seems like a lot of speed loss and interruption of other threads.
Link to comment
Share on other sites

  • 1 month later...

well i'm kinda noob with the scripts, so i have question: from where is the function "Thread_MsgLoop" beeing call?, i cant figure out, the script works perfectly but i wanna learn his logic to use it with a project that requires something near to multithread. tnx in advance.

Edited by bienmexicano

i love to draw so Go here!!!!!!!

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...