YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
DBUG_PUSH("d:t:O,/tmp/trace");
printf("This program is testing the mutex deadlock detection.\n" "It should print out different failures of wrong mutex usage" "on stderr\n\n");
/* Check that we don't get another warning for same lock */
printf("Testing A->B and B->A again (should not give a warning)\n");
pthread_mutex_lock(&LOCK_B);
pthread_mutex_lock(&LOCK_A);
pthread_mutex_unlock(&LOCK_A);
pthread_mutex_unlock(&LOCK_B);
/* Testofringwithmanymutex Wealsounlockmutexindifferentorderstogettheunlockcodeproperly tested.
*/
printf("Testing A->C and C->D and D->A\n");
pthread_mutex_lock(&LOCK_A);
pthread_mutex_lock(&LOCK_C);
pthread_mutex_unlock(&LOCK_A);
pthread_mutex_unlock(&LOCK_C);
pthread_mutex_lock(&LOCK_C);
pthread_mutex_lock(&LOCK_D);
pthread_mutex_unlock(&LOCK_D);
pthread_mutex_unlock(&LOCK_C);
pthread_mutex_lock(&LOCK_D);
pthread_mutex_lock(&LOCK_A); /* Should give warning */
printf("\nFollowing shouldn't give any warnings\n");
printf("Testing A->B and B->A without deadlock detection\n");
fflush(stdout);
/* Reinitialize mutex to get rid of old wrong usage markers */
pthread_mutex_destroy(&LOCK_A);
pthread_mutex_destroy(&LOCK_B);
pthread_mutex_init(&LOCK_A, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_B, MY_MUTEX_INIT_FAST);
printf("Testing A -> C ; B -> C ; A->B\n");
fflush(stdout);
pthread_mutex_lock(&LOCK_A);
pthread_mutex_lock(&LOCK_C);
pthread_mutex_unlock(&LOCK_C);
pthread_mutex_unlock(&LOCK_A);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.