hi
      i want to make my app multithreaded.i never go before this concept.i have a list of some urls,now i m visiting these urls sync
      and sequentially thru socket.i want to acheive this thing in multithreaded i.e visiting async and run 5 threads of different
      urls at a time.

      plz guide me how i acheive this thing,how i design a flow and which funcs help me to acheive this thing.i read some funcs
      regarding multithreading(CreateThread) may this help me in this thing.

      plz suggest me the site that helpz me in understanding multithreading.if some one guide me here with small snippets
      commented i m greatly thankful to him.

regards
AsmBeg
   
     
Posted on 2006-09-09 13:06:39 by AssemblyBeginner
Posted on 2006-09-09 19:42:51 by ti_mo_n
It's just a CreateThread(). Simple. An example, stripped from some of my code:

invoke CreateThread,0,10000,EasySound_AudioThread,0,0,addr temp1

temp1 is a dword, I don't ever use its data - it's just that the function requires it.
10000 is the initial stack space.
And the EasySound_AudioThread proc can be as simple as:

EasySound_AudioThread proc UnusedParam1
; .. do whatever here
ret ; after this return, the thread is destroyed
EasySound_AudioThread endp


One thing that iirc MSDN didn't mention directly was that created threads can take around 1 second to start! The CreateThread() returns in a millisecond, but EasySound_AudioThread() will/can be invoked much later.

To sync your data, use Critical Sections, (EnterCriticalSection(),... ). Their structure takes 24 bytes, but entering them takes just ~20 cycles usually. For many tiny objects, you can use your own locking scheme, based on the XCHG instruction.

Note that increasing the number of threads in some cases can become hell for synchronization. In more complex projects, at least. It's the reason for me to keep a minimum number of threads, and implement a FIFO "tail" to send commands to one main processing thread.
If you don't cope with many vectors (variable-sized arrays of pointers to objects), multithreading will be a breeze for you ;)
Posted on 2006-09-10 07:19:43 by Ultrano
i don't know that i have use CreateThread func correctly.the result is not correct may be the urldownload2file takes time???

invoke CreateThread ..,MyThread1..
invoke CreateThread ..,MyThread2..
invoke CreateThread ..,MyThread3..
invoke CreateThread ..,MyThread4..

Mythread1 proc
urldownload2file url1..
ret
Mythread1 endp
  ....
  ....
Mythread4 proc
urldownload2file url4..
ret
Mythread4 endp


plz guide me how to use in correct way
Posted on 2006-09-10 13:47:25 by AssemblyBeginner
First, your MythreadX procs must have 1 parameter, not none.
Monitor your network adapter to see if the urldownload2file does the downloading.
Remeber not to exit your app right after creating the threads.
Posted on 2006-09-10 13:51:29 by Ultrano
Doing this via multiple threads is pretty easy, but it would be better using a single thread and doing async calls.

Also, if you're using the wininet functions, remember that you'll be limited in the number of simultaneous connections you can make. If you're doing anything serious, it's better to write your own code.
Posted on 2006-09-10 14:56:20 by f0dder
thks ultrano and f0dder for giving replying.

f0dder u mean go for socket instead of this api and doing async jobs thru socket.
as i say i m new to this topic, i want to brush myself with threads want do u thing.

regards
AsmBeg
Posted on 2006-09-11 12:20:29 by AssemblyBeginner
Well, if you want multiple connections to a server, then yes - ultimately, you should code your own and do async instead of threads (ok, using a thread per connection isn't so bad if you're only making a few connections, but when you start having 100's or 1000's, a thread per connection is bad).

Doing all the HTTP stuff yourself is a bit of work, but you can look at stuff like libCurl for inspiration, if you can read C :)
Posted on 2006-09-11 17:25:25 by f0dder