 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
daniel2 Guest
|
Posted: Tue Jul 10, 2007 9:55 pm Post subject: |
|
|
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
Thanks for the response! |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Wed Jul 11, 2007 1:07 pm Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5581
|
Posted: Wed Jul 11, 2007 2:15 pm Post subject: |
|
|
Many thanks for the clarification Mr.Chris.
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  |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2383
|
Posted: Thu Jul 12, 2007 3:13 am Post subject: |
|
|
It looks like some worarounds for quirks are possible (although they might not work in the next version ). 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 |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2383
|
Posted: Thu Jul 12, 2007 4:13 am Post subject: |
|
|
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 |
|
 |
viciouskinid
Joined: 23 Jun 2007 Posts: 122
|
Posted: Tue Aug 28, 2007 5:56 pm Post subject: |
|
|
| is their a way to sent a variable to the thread like the path of the script %A_ScriptDir% |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6309 Location: Pacific Northwest, US
|
Posted: Tue Aug 28, 2007 6:20 pm Post subject: |
|
|
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 |
|
 |
RaptoR
Joined: 27 Jun 2007 Posts: 22 Location: Earth, Cambrian period
|
Posted: Mon Jan 21, 2008 12:13 pm Post subject: |
|
|
| 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!  |
It is not necessary to be that complex 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. Its concurrency model (called "actors") is quite simple but efficient. |
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 150
|
Posted: Tue Feb 19, 2008 9:49 pm Post subject: |
|
|
I know i'm a bit late, but how can I pass parameters when creating a thread? _________________
Watch my css video! |
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 150
|
Posted: Thu Feb 21, 2008 6:00 pm Post subject: |
|
|
Nobody?
I really need to know this. _________________
Watch my css video! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|