That's why i think it's a gcc problem, if i move the function to it's original place everything works!
I was wondering if there something lika a -mutex-across-multiple-source-files i should pass to gcc.
That's why i think it's a gcc problem, if i move the function to it's original place everything works!
I was wondering if there something lika a -mutex-across-multiple-source-files i should pass to gcc.
No, it's not gcc's fault - or anyone elses. You are passing a COPY of the mutex to "function" - this mutex is NOT the same one that you were using in the other code.
It's not because you are using multiple files, but simply that you are copying an existing mutex, and making it a different mutex.
should work.Code:void function(pthread_mutex_t *mut) { pthread_mutex_lock(mut); printf("This shows up if function is in the same source file as the calling code."); pthread_mutex_unlock(mut); } ... function(&mut);
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
It's more complicated that that. I simplified the example...
I'm passing this structure:
Into this function:Code:typedef struct { /* Country mutex structure */ pthread_mutex_t resA, resE, resP, resM; pthread_mutex_t purchase1, purchase2; } CountryMutex;
Using this call:Code:void findDeficit(const Config *config, const CountryStruct *country, CountryDeficit *cdeficit, CountryMutex *cmutex) { pthread_mutex_lock(&cmutex->resA); ... pthread_mutex_unlock(&cmutex->resA); }
Shouldn't this work? Passing a pointer to a structure of mutexes?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
Last edited by Quasar; 12-04-2007 at 07:58 AM. Reason: Wrong code
Your calling code doesn't look like it's passing pointers, so I'm not sure if it's at all working - but yes, passing a structure pointer that contains mutexes should work. The point is that you can't make copies of a mutex and still think that it's the same mutex.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Sorry, missing &.
Still the same problem, argh...
Rebooting the server, maybe that works.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.