Multi Thread Program Problem

This is a discussion on Multi Thread Program Problem within the C Programming forums, part of the General Programming Boards category; Hey, I'm developing a multi-threaded program in C. I have a thread - a dispatcher responsible for receiving information from ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    1

    Multi Thread Program Problem

    Hey,

    I'm developing a multi-threaded program in C.
    I have a thread - a dispatcher responsible for receiving information from a pipe and sending it to three other threads
    I used conditional variables to (try) to synchronize the program, but I'm having some problems.

    For a start I used pthread_cond_signal()

    Code:
    Multi Thread Program
    //dispatcher
    pthread_cond_signal(&cond)
    
    //thread1
    while (letMeWork == 0) {
             puts("COMPRESSOR BLOCKED");
             pthread_cond_wait(&cond, &mutex)
          }
          printf("[COMPRESSOR]");
    
    //thread2
    while (letMeWork == 0) {
             puts("ENCRYPTOR BLOCKED");
             pthread_cond_wait(&cond, &mutex)
          }
          printf("[ENCRYPTOR]");
    ...
    What I'm trying to do is: when I receive something in the pipe (the filename) the thread dispatcher sends a signal to thread1 in order for this to compress the file, after that the thread2 will work in that same file (modified by thread1).
    Note, I could have different files, so thread1 is compressing one file and thread2 is encrypting another.

    The problem is that, after receiving a signal, only thread1 works.
    I've tried with broadcast() but in that case it's worse...

    Any help is very welcome,

    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Perhaps I've gotten confused in the description, but don't you need two signals -- dispatcher sends a signal to compressor and compressor sends a signal to encryptor?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 09:37 PM
  3. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  4. Comment this Program
    By kishorepalle in forum C Programming
    Replies: 11
    Last Post: 10-05-2004, 06:41 AM
  5. Program abort due to memory problem
    By cazil in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2002, 11:55 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21