Thread: Mutex across multiple source files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Registered User
    Join Date
    May 2004
    Posts
    19
    It's more complicated that that. I simplified the example...

    I'm passing this structure:

    Code:
    typedef struct {        /* Country mutex structure */
            pthread_mutex_t resA, resE, resP, resM;
            pthread_mutex_t purchase1, purchase2;
    } CountryMutex;
    Into this function:
    Code:
     
    void findDeficit(const Config *config, const CountryStruct *country, CountryDeficit *cdeficit, CountryMutex *cmutex) {
    pthread_mutex_lock(&cmutex->resA);
    ...
    pthread_mutex_unlock(&cmutex->resA);
    }
    Using this call:
    Code:
    CountryMutex cmutex;
    pthread_mutex_init(&cmutex.resA, NULL);
    pthread_mutex_init(&cmutex.resE, NULL);
    pthread_mutex_init(&cmutex.resP, NULL);
    pthread_mutex_init(&cmutex.resM, NULL);
    
    findDeficit(config, country, cdeficit, &cmutex);   << EDIT
    Shouldn't this work? Passing a pointer to a structure of mutexes?
    Last edited by Quasar; 12-04-2007 at 07:58 AM. Reason: Wrong code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple source files in one project
    By mintsmike in forum C++ Programming
    Replies: 8
    Last Post: 06-27-2009, 07:20 AM
  2. Confusion on header and source files
    By dnguyen1022 in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2009, 03:42 AM
  3. Working with multiple source files
    By abh!shek in forum C Programming
    Replies: 17
    Last Post: 06-03-2008, 11:23 AM
  4. Multiple Source Files!?!?
    By Padawan in forum C Programming
    Replies: 14
    Last Post: 04-04-2004, 12:19 AM
  5. Replies: 1
    Last Post: 05-01-2003, 02:52 PM