xroot Posted January 15, 2009 Share Posted January 15, 2009 Someone posted this web site about multithreading.http://www.devarticles.com/c/a/Cplusplus/Multithreading-in-C/ It said, "a multithreaded program executes portions of itself concurrently.""All multithreaded programs include an element of parallelism.""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.""Each multithreaded process starts with one thread of execution and then creates one or more additional threads.""In a properly designed program, each thread represents a single logical unit of activity.""A major issue in multithreaded programs is managing the interaction of the threads."With all this in mind I created this little script to see if multithreading is possible, emphasize on managing the threads.My example is simple which makes me think multithreading will work fine in au3.After you click ok on the first msgbox, move each msgbox so you can see all four threads.multithread.zip Link to comment Share on other sites More sharing options...
weaponx Posted January 15, 2009 Share Posted January 15, 2009 How does this differ from the version ProgAndy wrote?http://www.autoitscript.com/forum/index.ph...hl=CreateThread Link to comment Share on other sites More sharing options...
ptrex Posted January 16, 2009 Share Posted January 16, 2009 @xroot This looks interesting. BUT I doubt that this is the real multithreading. When you add this at the end of your code. You can indead see that it generated 4 threads. ; --------------------------------------- Thread info -------------------------------------------------------- $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colProcessList = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process Where Name = 'AutoIt3.exe'") For $objProcess in $colProcessList ConsoleWrite("Process: " & $objProcess.Name & @LF) ConsoleWrite("Process ID: " & $objProcess.ProcessID & @LF) ConsoleWrite( "Thread Count: " & $objProcess.ThreadCount& @LF) ConsoleWrite( @LF) Next But when I add this code the ANY other AU3 script. I get much higher number of threads to see ? Give it a try. Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
JRSmile Posted January 16, 2009 Share Posted January 16, 2009 (edited) this is nice, you just have to figure out how to call one thread many times with different parameters.. at the same time and how to recieve the return values.... Edited January 16, 2009 by JRSmile $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
torels Posted January 16, 2009 Share Posted January 16, 2009 it's quite a stupid thing but I put it in a function to use it whenever you want _NewThread("_hello") _NewThread("_goodbye") MsgBox(0,"","Main thread") ;you have to do something in the main thread or children threads will be closed and nothing will happen Func _NewThread($sFunctionName) Local $TP,$T,$hT=DllStructCreate("hwnd[1]"),$phT=DllStructGetPtr($hT) $TP=DLLCallbackRegister($sFunctionName,"int","int") $T=DllStructCreate("int") $Thread=DllCall("Kernel32.dll","hwnd","CreateThread","ptr",0, _ "int",0, _ "ptr",DllCallbackGetPtr($TP), _ "int",0, _ "int",0, _ "ptr",DllStructGetPtr($T)) DllStructSetData($hT,1,$Thread[0],1) DllCall("Kernel32.dll","int","CloseHandle","hwnd",DllStructGetData($hT,1,1)) EndFunc Func _hello($handle) MsgBox(0,"","hello") EndFunc Func _goodbye($handle) MsgBox(0,"","goodbye") EndFunc Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org Link to comment Share on other sites More sharing options...
udgeen Posted January 16, 2009 Share Posted January 16, 2009 As far as i know, autoit is not "thread-safe". It meens we'll have no working multithread au3. msgbox() might be the only thread-safe func. I've just tested example and realised, that even consolewrite is not thread-safe: i got system errors in random... Link to comment Share on other sites More sharing options...
youknowwho4eva Posted January 16, 2009 Share Posted January 16, 2009 I wouldn't say that msgbox is safe either _NewThread("_hello") _NewThread("_goodbye") MsgBox(0,"","Main thread");you have to do something in the main thread or children threads will be closed and nothing will happen Func _NewThread($sFunctionName) Local $TP,$T,$hT=DllStructCreate("hwnd[1]"),$phT=DllStructGetPtr($hT) $TP=DLLCallbackRegister($sFunctionName,"int","int") $T=DllStructCreate("int") $Thread=DllCall("Kernel32.dll","hwnd","CreateThread","ptr",0, _ "int",0, _ "ptr",DllCallbackGetPtr($TP), _ "int",0, _ "int",0, _ "ptr",DllStructGetPtr($T)) DllStructSetData($hT,1,$Thread[0],1) DllCall("Kernel32.dll","int","CloseHandle","hwnd",DllStructGetData($hT,1,1)) EndFunc Func _hello($handle) MsgBox(0,"","hello",7) EndFunc Func _goodbye($handle) MsgBox(0,"","goodbye",4) EndFunc Giggity Link to comment Share on other sites More sharing options...
WolfWorld Posted January 16, 2009 Share Posted January 16, 2009 This very good but it DOES NOT take full advantage of multithread, the only way to do this add a source code to the autoit it self. And autoit should have a value communication build in. But ya its a very good ex. but too many error Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
Kip Posted January 16, 2009 Share Posted January 16, 2009 Nah, doesn't work. CODE_NewThread("_hello") _NewThread("_goodbye") While 1 WEnd Func _hello($handle) $gui = GUICreate("win 1",400,300,0) $Button = GUICtrlCreateButton("Hover",50,50,80,23) GUISetState(@SW_SHOW) $iOver = 0 While 1 $array = GUIGetCursorInfo($gui) if $array[4] = $Button Then if not $iOver Then GUICtrlSetData($Button,"Hovering") $iOver = 1 EndIf Else If $iOver Then GUICtrlSetData($Button,"Hover") $iOver = 0 EndIf EndIf WEnd EndFunc Func _goodbye($handle) $gui = GUICreate("win 1",400,300,0) $Button = GUICtrlCreateButton("Hover",50,50,80,23) GUISetState(@SW_SHOW) $iOver = 0 While 1 $array = GUIGetCursorInfo($gui) if $array[4] = $Button Then if not $iOver Then GUICtrlSetData($Button,"Hovering") $iOver = 1 EndIf Else If $iOver Then GUICtrlSetData($Button,"Hover") $iOver = 0 EndIf EndIf WEnd EndFunc Func _NewThread($sFunctionName) Local $TP,$T,$hT=DllStructCreate("hwnd[1]"),$phT=DllStructGetPtr($hT) $TP=DLLCallbackRegister($sFunctionName,"int","int") $T=DllStructCreate("int") $Thread=DllCall("Kernel32.dll","hwnd","CreateThread","ptr",0, _ "int",0, _ "ptr",DllCallbackGetPtr($TP), _ "int",0, _ "int",0, _ "ptr",DllStructGetPtr($T)) DllStructSetData($hT,1,$Thread[0],1) DllCall("Kernel32.dll","int","CloseHandle","hwnd",DllStructGetData($hT,1,1)) EndFunc MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now