Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to write a correct Multi Threaded Application [modified]

how to write a correct Multi Threaded Application [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpdesigntutoriallounge
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swarup
    wrote on last edited by
    #1

    hi guys, i have a dialog application, i want to launch 10 worker thread and each worker thread will do a particular work, ie. each worker thread will connect to a url and download the page content, and they will parse the page and write some data to a database, so imagine if there are 1000 pages then if i go by general way of geting pages one by one it will take me around 20 mins to 45 mins, so i was thinking if launch 10 thread which in term each will collect 1 page then the time may be reduced, my problem or query is, as fas of today is, we all using single processor, so no matter how many threads u create, any given point of time only one instruction will carried out, but when i launch more then one application of mine and break up the collection say app1 collects 100 and app2 collects another 100, this is faster then collecting 1000 in 1 application, so breakin it to threads will help or not, how to code for it, do you have any idea i mean any design for it, or any help for it, cas i cant write 10 diff function for each thread,i want one function to do all the work but i will pass diff parameter for each thread, but then comes the problem resource access violation if i call the same function for each thread, so is there a way i can the thread callback to a class, or i can put the whole code, for say class mythrdcls { mythrdcls(char *) {} void create(){} void dothetask(){}// like a thread callback function void running(){} void destroy(){} } so please give me an idea how to do it, ya one more thing i forgot to add here, when i call createthread or afxbeginthread, i have to call a thread callback, i want to pass some arguments to my thread callback funcion, so i can pass them in param value, i want to pass more then one value so i have to create a structure and pass it, but the problem is in thread function it does not reflect the correct value, ie struct th { int x;int y} x; x.y=10,x.x=1 beginthread(function1, x); x.y=20,x.x=2 beginthread(function2, x); function1() a=x; a.x///////////does not alwys contain 1 ie cas by the time callback is called the value is changed to 2 so how can make sure tht unless the thread callback is called the 2nd thread cant be created or ast thread get the corect value and so 2nd thread also, i used waitforsingleobject but it did not help Thanks a lot

    S 1 Reply Last reply
    0
    • S swarup

      hi guys, i have a dialog application, i want to launch 10 worker thread and each worker thread will do a particular work, ie. each worker thread will connect to a url and download the page content, and they will parse the page and write some data to a database, so imagine if there are 1000 pages then if i go by general way of geting pages one by one it will take me around 20 mins to 45 mins, so i was thinking if launch 10 thread which in term each will collect 1 page then the time may be reduced, my problem or query is, as fas of today is, we all using single processor, so no matter how many threads u create, any given point of time only one instruction will carried out, but when i launch more then one application of mine and break up the collection say app1 collects 100 and app2 collects another 100, this is faster then collecting 1000 in 1 application, so breakin it to threads will help or not, how to code for it, do you have any idea i mean any design for it, or any help for it, cas i cant write 10 diff function for each thread,i want one function to do all the work but i will pass diff parameter for each thread, but then comes the problem resource access violation if i call the same function for each thread, so is there a way i can the thread callback to a class, or i can put the whole code, for say class mythrdcls { mythrdcls(char *) {} void create(){} void dothetask(){}// like a thread callback function void running(){} void destroy(){} } so please give me an idea how to do it, ya one more thing i forgot to add here, when i call createthread or afxbeginthread, i have to call a thread callback, i want to pass some arguments to my thread callback funcion, so i can pass them in param value, i want to pass more then one value so i have to create a structure and pass it, but the problem is in thread function it does not reflect the correct value, ie struct th { int x;int y} x; x.y=10,x.x=1 beginthread(function1, x); x.y=20,x.x=2 beginthread(function2, x); function1() a=x; a.x///////////does not alwys contain 1 ie cas by the time callback is called the value is changed to 2 so how can make sure tht unless the thread callback is called the 2nd thread cant be created or ast thread get the corect value and so 2nd thread also, i used waitforsingleobject but it did not help Thanks a lot

      S Offline
      S Offline
      swarup
      wrote on last edited by
      #2

      thanks anyway,for no reply, figured it out myself, any one need help in tht case let me knw

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups