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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. pthread in c++ (LINUX)

pthread in c++ (LINUX)

Scheduled Pinned Locked Moved C / C++ / MFC
c++linuxquestion
3 Posts 2 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.
  • Q Offline
    Q Offline
    quixqx
    wrote on last edited by
    #1

    Hi I wrote a code that has multiple threads, each thread has to run independent of another and complete at different times. I tried using the sleep() function to delay execution for some seconds but the program terminates while threads are still sleeping. I also tried using usleep() function, its works fine with small parameters but behave the same as sleep() with large parameters. Is there anyway that I can delay program termination until my threads are awake and have completed there task? OR Is there a better way of delaying the threads other than using sleep() and usleep()? Thanx

    M 1 Reply Last reply
    0
    • Q quixqx

      Hi I wrote a code that has multiple threads, each thread has to run independent of another and complete at different times. I tried using the sleep() function to delay execution for some seconds but the program terminates while threads are still sleeping. I also tried using usleep() function, its works fine with small parameters but behave the same as sleep() with large parameters. Is there anyway that I can delay program termination until my threads are awake and have completed there task? OR Is there a better way of delaying the threads other than using sleep() and usleep()? Thanx

      M Offline
      M Offline
      markkuk
      wrote on last edited by
      #2

      Call pthread_join()[^] for each thread you have created before your main program exits.

      Q 1 Reply Last reply
      0
      • M markkuk

        Call pthread_join()[^] for each thread you have created before your main program exits.

        Q Offline
        Q Offline
        quixqx
        wrote on last edited by
        #3

        thanx, I do pthread_join() call for all my threads but the sleeping ones do not get there. From the sample file, I have to create about five thread, only two are required to delay. The delayed threads do not get to the pthread_join() call but the other three get there. Seems the programs continues running as if there are no sleeping threads.

        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