Archive: Doing more than one thing at once - threading.


Doing more than one thing at once - threading.
I'm new to NSIS, and after struggling a bit with the scripting language, I've now figured out how to do all the things I need to do except one:

I want the installer to be able to do multiple things at once (effectively multi threading), and I want each "thread" to be able to check the progress of the other things going on at the same time.

An example is if I want to download a file (bandwidth intensive), extract a compressed file (CPU intensive), and copy a large file (HD intensive) all at the same time, so the installer completes faster.

So say for my script (this is sudocode):


NSISdl::startDownload("http://abc.com/myfile")
Copyfile::Start "filea.iso" "fileb.iso"
Zip::StartExtract "bigzip.zip" "*.*"

loop:
progress=(NSISdl::progress)+(CopyFile::progress)+(Zip::progress) / 3
if (NSISdl::done)&&(CopyFile::done)&&(Zip::done) goto done
delay 1000
goto loop

done:
msgbox("everythings done")


Is that possible, preferably without too many modiications to sll the c++ modules?

I'm afraid not. The only way to run NSIS code simultaneously is to have each thread as a separate executable and execute each of them silently with Exec. The easiest way to check when they are all done would be to check registry entries every few seconds (Sleep) in a loop.

Something like this:

Exec "$PLUGINSDIR\thread1.exe"
Exec "$PLUGINSDIR\thread2.exe"
Exec "$PLUGINSDIR\thread3.exe"
Loop:
ReadRegStr $R1 "Software\MyApp\Install\Thread1" ""
ReadRegStr $R2 "Software\MyApp\Install\Thread2" ""
ReadRegStr $R3 "Software\MyApp\Install\Thread3" ""
Sleep 5000
StrCmp $R1 0 Loop
StrCmp $R2 0 Loop
StrCmp $R3 0 Loop


-Stu

Is there any way to make those seperate "Thread" exeutables with NSIS, and then have them silent executables without a ui?


You can write a plug-in, for example Marquee does the threads trick. Plug-ins can work without gui.


Yes, just put SilentInstall Silent in those scripts.
You won't be able to execute separate NSIS code with plugins however, only C/C++ code.

-Stu