Find the answer to your Linux question:
Results 1 to 2 of 2
thread question... i have 2 threads.. 1 will execute and begin reading a file, when the thread encounters a space the thread will pause, at this point the second thread ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    3

    Pausing a thread

    thread question... i have 2 threads.. 1 will execute and begin reading a file, when the thread encounters a space the thread will pause, at this point the second thread will begin executing.. this goes back and forth.. Anyways i am looking for a way of pausing the threads execution so the other thread can execute.. write now I:
    ....
    pthread_cond_signal
    pause by usleeping
    ...
    ..

    this works fairly well for shorter files but eventually the timing gets a little bit off and some words get mixed up.

    thanks

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Quoth static_cast:
    eventually the timing gets a little bit off
    Raise your expectations! Either the synchronization between the two threads works perfectly, or the program's broken, in ways that can be really perplexing, expensive, and dangerous (in the real world) eventually. It's best to nail each timing problem aggressively!

    You don't want to pause by usleeping. You want pthread_cond_wait().

    Hope this helps.

Posting Permissions

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