1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | (gdb) thread apply 1 where Thread 1 (Thread 1073991712 (LWP 9510)): #0 0x0ff4ac40 in __write_nocancel () from /lib/tls/libc.so.6 #1 0x0ff4ac28 in __write_nocancel () from /lib/tls/libc.so.6 Previous frame identical to this frame (corrupt stack?) #0 0x0ff4ac40 in __write_nocancel () from /lib/tls/libc.so.6 (gdb) thread apply 2 where Thread 2 (Thread 1090771744 (LWP 9514)): #0 0x0ffe94ec in __lll_lock_wait () from /lib/tls/libpthread.so.0 #1 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #2 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #3 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #4 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 Previous frame inner to this frame (corrupt stack?) #0 0x0ff4ac40 in __write_nocancel () from /lib/tls/libc.so.6 (gdb) thread apply 3 where Thread 3 (Thread 1086577440 (LWP 9513)): #0 0x0ffe94ec in __lll_lock_wait () from /lib/tls/libpthread.so.0 #1 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #2 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #3 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #4 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 Previous frame inner to this frame (corrupt stack?) #0 0x0ff4ac40 in __write_nocancel () from /lib/tls/libc.so.6 (gdb) thread apply 4 where Thread 4 (Thread 1082383136 (LWP 9512)): #0 0x0ffe94ec in __lll_lock_wait () from /lib/tls/libpthread.so.0 #1 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #2 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #3 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #4 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 Previous frame inner to this frame (corrupt stack?) #0 0x0ff4ac40 in __write_nocancel () from /lib/tls/libc.so.6 (gdb) thread apply 5 where Thread 5 (Thread 1078188832 (LWP 9511)): #0 0x0ffe94ec in __lll_lock_wait () from /lib/tls/libpthread.so.0 #1 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #2 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #3 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 #4 0x0ffe466c in pthread_mutex_lock () from /lib/tls/libpthread.so.0 Previous frame inner to this frame (corrupt stack?) #0 0x0ff4ac40 in __write_nocancel () from /lib/tls/libc.so.6 |
1 2 3 4 5 6 7 8 9 10 11 | (gdb) print AccountA_mutex $1 = {__m_reserved = 2, __m_count = 0, __m_owner = 0x2527, <br> __m_kind = 0, __m_lock = {__status = 1, __spinlock = 0}} (gdb) print 0x2527 $2 = 9511 (gdb) print AccountB_mutex $3 = {__m_reserved = 2, __m_count = 0, __m_owner = 0x2529, <br> __m_kind = 0, __m_lock = {__status = 1, __spinlock = 0}} (gdb) print 0x2529 $4 = 9513 (gdb) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | . . void * transferAB (void* amount_ptr) { int amount = *((int*)amount_ptr); pthread_mutex_lock(&AccountA_mutex); pthread_mutex_lock(&AccountB_mutex); if (accountA.balance < amount) { printf("There is not enough memory in Account A!\n"); pthread_mutex_unlock(&AccountA_mutex); pthread_exit((void *)1); } accountA.balance -=amount; sleep(1); accountB.balance +=amount; pthread_mutex_unlock(&AccountA_mutex); pthread_mutex_unlock(&AccountB_mutex); } void * transferBA (void* amount_ptr) { int amount = *((int*)amount_ptr); pthread_mutex_lock(&AccountA_mutex); pthread_mutex_lock(&AccountB_mutex); if (accountB.balance < amount) { printf("There is not enough memory in Account B!\n"); pthread_mutex_unlock(&AccountB_mutex); pthread_exit((void *)1); } accountB.balance -=amount; sleep(1); accountA.balance +=amount; pthread_mutex_unlock(&AccountA_mutex); pthread_mutex_unlock(&AccountB_mutex); } . . |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | . . void * transferAB (void* amount_ptr) { int amount = *((int*)amount_ptr); pthread_mutex_lock(&AccountA_mutex); if (accountA.balance < amount) { printf("There is not enough memory in Account A!\n"); pthread_mutex_unlock(&AccountA_mutex); pthread_exit((void *)1); } accountA.balance -=amount; sleep(1); pthread_mutex_unlock(&AccountA_mutex); pthread_mutex_lock(&AccountB_mutex); accountB.balance +=amount; pthread_mutex_unlock(&AccountB_mutex); } void * transferBA (void* amount_ptr) { int amount = *((int*)amount_ptr); pthread_mutex_lock(&AccountB_mutex); if (accountB.balance < amount) { printf("There is not enough memory in Account B!\n"); pthread_mutex_unlock(&AccountB_mutex); pthread_exit((void *)1); } accountB.balance -=amount; sleep(1); pthread_mutex_unlock(&AccountB_mutex); pthread_mutex_lock(&AccountA_mutex); accountA.balance +=amount; pthread_mutex_unlock(&AccountA_mutex); } . . . |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |