AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

real thread handling
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
daniel2
Guest





PostPosted: Tue Jul 10, 2007 9:55 pm    Post subject: Reply with quote

Interesting. I noticed that the thread ID's are always 8 apart. I'm thinking that the 4 limit must be related to how AHK internally handles its own threads & maybe your trying to tap into something that is reserved...
New internal ahk threads do get spawned using dll method..(like hotkey/context menu.. etc) but using Loop the threads still seem to use the thread-queue as described in help Confused

Thanks for the response!
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Wed Jul 11, 2007 1:07 pm    Post subject: Reply with quote

I've no idea why it would be limited to 3 threads per script. However, AutoHotkey isn't designed to support multiple threads except in the case of the keyboard/mouse hook (which both share a second thread when they're active). Therefore, AutoHotkey isn't thread-safe, particularly when it comes to reading/writing variables. Therefore if the second thread does anything that interferes with something the main thread is doing (or vice versa), using multiple threads in a script might cause unexpected behavior or possibly even crashes.

It's also possible there could be other problems just from the mere existence of a second thread that is running parts of the script in parallel with the main thread. The program simply isn't designed to do that. An extensive code-review would be necessary if anyone wants to verify that it's safe.

AutoHotkey doesn't currently support multiple process-threads due to the need to make many sections thread-safe, which in turn would:
1) Increase code size.
2) Reduce performance in many areas due to the need to enforce thread-safety.
3) Be very costly in development time (probably 4-8 weeks of full-time work).
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 5581

PostPosted: Wed Jul 11, 2007 2:15 pm    Post subject: Reply with quote

Many thanks for the clarification Mr.Chris. Smile

I guess my application exceptionally escapes the evil with a second parallel thread.
I will send you a copy of my code before I post it in S & F.

Thanks again Smile
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2383

PostPosted: Thu Jul 12, 2007 3:13 am    Post subject: Reply with quote

It looks like some worarounds for quirks are possible Smile (although they might not work in the next version Wink ). For instance, Loop seems to work ok but specifying the number of times to Loop with the Loop command does not seem to work.
Code:
#Persistent
CoordMode, ToolTip, Screen
CBA_FirstLoop := RegisterCallback( "FirstLoop" )
CBA_SecondLoop := RegisterCallback( "SecondLoop" )
DllCall( "CreateThread", UInt,0, UInt,0, UInt,CBA_FirstLoop, UInt,0, UInt,0, UInt,0 )
DllCall( "CreateThread", UInt,0, UInt,0, UInt,CBA_SecondLoop, UInt,0, UInt,0, UInt,0 )
return

FirstLoop() {
  X := 0

  Loop 
  {
     X += 1
    If (X > 40) {
     Tooltip,,, 1
     Exit
   }
    MouseGetPos, OutX, OutY
     ToolTip, X = %X%,,(OutY - 10), 1
    Sleep, 200   
  }
  Return
}

SecondLoop()  {
  Y := 2
  c := (Y)**40
  Loop
  {
     Y *= 2
    If (Y > c) {
     Tooltip,,, 2
     Exit
   }
    MouseGetPos, OutX, OutY
     ToolTip Y = %Y%,,(OutY + 10), 2
    Sleep, 150
  }
  Return
}

Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2383

PostPosted: Thu Jul 12, 2007 4:13 am    Post subject: Reply with quote

Unfortunately, this trick does not work as well if you compile AutoHotkey using VC++ 2005 Express. It seems to break at the first If statement.
Edit: hmm, it seems to only run for a brief moment then break with most lines of code...
Back to top
View user's profile Send private message Visit poster's website
viciouskinid



Joined: 23 Jun 2007
Posts: 122

PostPosted: Tue Aug 28, 2007 5:56 pm    Post subject: Reply with quote

is their a way to sent a variable to the thread like the path of the script %A_ScriptDir%
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6309
Location: Pacific Northwest, US

PostPosted: Tue Aug 28, 2007 6:20 pm    Post subject: Reply with quote

you could maybe use Majkinetors IPC module for interprocess communication. you may be able to communicate between the threads that way.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
RaptoR



Joined: 27 Jun 2007
Posts: 22
Location: Earth, Cambrian period

PostPosted: Mon Jan 21, 2008 12:13 pm    Post subject: Reply with quote

PhiLho wrote:
Thread programming is known to be tricky and quite complex: after running tasks in parallels, people will ask ways to synchronize threads, to share data between threads, and so on. A real Pandora box! Smile


It is not necessary to be that complex Smile Take a look at Erlang, the language that was used by a lot of people who created software with very high level of concurrency (esp. telecom requires this). You might be surprised, but there is no synchronization, data sharing between threads and so on in Erlang. Smile Its concurrency model (called "actors") is quite simple but efficient.
Back to top
View user's profile Send private message
Jero3n



Joined: 19 Jan 2007
Posts: 150

PostPosted: Tue Feb 19, 2008 9:49 pm    Post subject: Reply with quote

I know i'm a bit late, but how can I pass parameters when creating a thread?
_________________

Watch my css video!
Back to top
View user's profile Send private message
Jero3n



Joined: 19 Jan 2007
Posts: 150

PostPosted: Thu Feb 21, 2008 6:00 pm    Post subject: Reply with quote

Nobody?
I really need to know this.
_________________

Watch my css video!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group