Results 1 to 5 of 5

Thread: Multi-thread programming help ??? any introduction??

  1. #1

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524

    Talking Multi-thread programming help ??? any introduction??

    Can anyone tell me how to do multi-thread programming in C/C++ with some simple examples?

    Suppose I have a file with 1000 records. Using conventional processing, I can apply a while not end of file reached, read and process each line.

    Is it possible using multi-thread programming, that I process the file under say 10 threads, so entire processing will be 10 times faster?

    Thanks in advance!
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Only if you have 10 CPUs. If you only have one then using it for things like that will slow it down.

    Multiple threads aren't always the best way, but in some cases they help. For example, if you have your interface, you have one thread handling user input, then the other goes off and does your 1000 records or whatever. It'll still have to go through all 1000 records, so it might as well do them start-to-finish.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524
    Could you still explain how to use multi-threading (if I have multiple CPUs, will it transfer different threads to different CPUs automatically?)

    VB.NET supports multi-threading quite easy manner. Is it that you always need multiple CPUs to take advantage of multi-threading?

    I am currently working in a data warehousing ETL (extraction transform loading) tool named Ab Initio (www.abinitio.com). They claim that this application can process enourmous data very fast using parallel processing technology. However, Ab Initio never discloses their architecture (unlike Oracle or SQL Server etc.) So, I'm wondering how they do process data parallelly. Is the parallel processing and multi-threading same? Is it that one always multiple CPUs to take advantage of multi-threading?
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Multithreading actually runs *slower* in absolute time, but frequently gives much better responses (you can control the execution from an interface).

    If you have multiple CPUs then multiple threads will get scheduled concurrently. You can only have *one* thread running at once on a single CPU, they just get switched very quickly.

    The easiest way of doing multithreading is to use the Boost Threads classes (www.boost.org). But, for simple things, use _beginthread (see MSDN). It's fairly self-explanatory
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    _beginthreadex for advanced options, or CreateThread API, but then you should not use any CRT functions in this thread (some of them, like strtok, rely on initialization done in _beginthreadex and won't behave correctly if you don't use it).

    Multithreading on single-CPU computers has, like parksie said, the advantage of keeping your app responsive while some background thread executes a lengthy operation. The windows programming guidelines say that for every operation that takes longer that 1/10th of a second you should either split it into shorter operations or create a thread that performs the operation.

    Look at any browser. It stays responsive even though it is waiting for data to arrive from the web. Why? Because the connection is handled in a seperate thread.

    Win2k will automatically distribute threads to all cpus if available. Win9x doesn't support multiple cpus.

    Parallel processing and multi-threading is not the same, although the latter is often implemented using the former. How Ab Inition does it I don't know.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width