Fw: [問題] Linux C多執行緒的疑問!?
※ [本文轉錄自 C_and_CPP 看板 #1JOU9vFQ ]
作者: BIAO (超越自己) 看板: C_and_CPP
標題: [問題] Linux C多執行緒的疑問!?
時間: Thu May 1 13:58:15 2014
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
-------------------------------
各位板友大家好,
目前小弟有個程式,內有A、B兩個thread,共用某個副程式,
其中A thread固定時間會執行該副程式,
另個B thread則隨機等候外部命令,接收外部命令後執行該副程式。
此程式在Linux內執行,
可有時候會自己中斷執行,
請問這是因為沒使用mutex,
發生衝突導致程式結束嗎!?
另想請問板友...
有什麼因素導致程式執行時,會自動結束呢!?
還請板友不吝賜教,謝謝..XD
--
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.124.42.70
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1398923897.A.3DA.html
※ 編輯: BIAO (140.124.42.70), 05/01/2014 14:15:52
推
05/01 20:10, , 1F
05/01 20:10, 1F
推
05/01 22:04, , 2F
05/01 22:04, 2F
→
05/01 22:05, , 3F
05/01 22:05, 3F
→
05/02 11:30, , 4F
05/02 11:30, 4F
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 轉錄者: BIAO (140.124.42.70), 05/02/2014 11:30:46
→
05/02 11:53, , 5F
05/02 11:53, 5F
→
05/02 11:53, , 6F
05/02 11:53, 6F
→
05/02 13:00, , 7F
05/02 13:00, 7F
→
05/02 13:32, , 8F
05/02 13:32, 8F
→
05/02 13:33, , 9F
05/02 13:33, 9F
→
05/02 13:50, , 10F
05/02 13:50, 10F
→
05/02 14:50, , 11F
05/02 14:50, 11F
回b大的話...
我都是用vim編輯C code,
用gcc編譯後,直接用sudo ./執行程式..
偶爾加個&來背景執行.. XD
※ 編輯: BIAO (140.124.42.70), 05/02/2014 15:04:57
→
05/02 15:10, , 12F
05/02 15:10, 12F
→
05/02 15:11, , 13F
05/02 15:11, 13F
→
05/02 15:16, , 14F
05/02 15:16, 14F
→
05/02 15:20, , 15F
05/02 15:20, 15F
→
05/02 16:16, , 16F
05/02 16:16, 16F
目前已經完全懂b大的意思..
我的確是在interactive mode執行程式,
不過就算執行沒加上&,程序自行結束時也沒有產生程序如何結束..
我是使用Ubuntu Linux,目前在尋找產生Core dump的方法XD
C語言程序是無窮迴圈,二個thread都是..
※ 編輯: BIAO (140.124.42.70), 05/02/2014 21:25:13
※ 編輯: BIAO (140.124.42.70), 05/02/2014 21:26:33
→
05/02 21:51, , 17F
05/02 21:51, 17F
→
05/02 22:46, , 18F
05/02 22:46, 18F
→
05/02 22:46, , 19F
05/02 22:46, 19F
→
05/02 23:21, , 20F
05/02 23:21, 20F
→
05/02 23:21, , 21F
05/02 23:21, 21F
→
05/02 23:23, , 22F
05/02 23:23, 22F
感謝大家的回覆,參照k大做法,
採用gcc -o -g -DDEBUG modbus+MySQL+Control26 modbus+MySQL+Control26.c
-I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lpthread,
得到了許多資訊..
-------------------------------------
modbus+MySQL+Control26: In function `_fini':
crtstuff.c:(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o:(.fini+0x0):
first defined here
modbus+MySQL+Control26: In function `__data_start':
crtstuff.c:(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.data+0x0):
first defined here
modbus+MySQL+Control26: In function `__data_start':
crtstuff.c:(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/crtbegin.o:(.data+0x0): first defined
here
modbus+MySQL+Control26:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.rodata.cst4+0x0):
first defined here
modbus+MySQL+Control26: In function `_start':
crtstuff.c:(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o:(.text+0x0):
first defined here
modbus+MySQL+Control26: In function `_init':
crtstuff.c:(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o:(.init+0x0):
first defined here
/tmp/ccj4NCbh.o:(.bss+0x0): multiple definition of `data_lock'
modbus+MySQL+Control26:(.bss+0x10): first defined here
/tmp/ccj4NCbh.o: In function `sock_server_thread':
modbus+MySQL+Control26.c:(.text+0x0): multiple definition of
`sock_server_thread'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:38:
first defined here
/tmp/ccj4NCbh.o: In function `order_dec':
modbus+MySQL+Control26.c:(.text+0x3f4): multiple definition of `order_dec'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:154:
first defined here
/tmp/ccj4NCbh.o: In function `control':
modbus+MySQL+Control26.c:(.text+0x7f4): multiple definition of `control'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:248:
first defined here
/tmp/ccj4NCbh.o: In function `status':
modbus+MySQL+Control26.c:(.text+0x2098): multiple definition of `status'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:697:
first defined here
/tmp/ccj4NCbh.o: In function `info':
modbus+MySQL+Control26.c:(.text+0x1204): multiple definition of `info'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:469:
first defined here
/tmp/ccj4NCbh.o: In function `main':
modbus+MySQL+Control26.c:(.text+0x378): multiple definition of `main'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:132:
first defined here
/tmp/ccj4NCbh.o: In function `modbustcp':
modbus+MySQL+Control26.c:(.text+0x2c20): multiple definition of `modbustcp'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:898:
first defined here
/tmp/ccj4NCbh.o: In function `modbusrtu':
modbus+MySQL+Control26.c:(.text+0x2f1c): multiple definition of `modbusrtu'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:1004:
first defined here
/tmp/ccj4NCbh.o: In function `info_insert':
modbus+MySQL+Control26.c:(.text+0x1c88): multiple definition of `info_insert'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:636:
first defined here
/tmp/ccj4NCbh.o: In function `cost_power':
modbus+MySQL+Control26.c:(.text+0x1e1c): multiple definition of `cost_power'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:660:
first defined here
/tmp/ccj4NCbh.o: In function `status_insert':
modbus+MySQL+Control26.c:(.text+0x2844): multiple definition of
`status_insert'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:839:
first defined here
/tmp/ccj4NCbh.o: In function `crc16':
modbus+MySQL+Control26.c:(.text+0x321c): multiple definition of `crc16'
modbus+MySQL+Control26:/home/ubuntu/C-practice/Test/modbus+MySQL+Control26.c:1114:
first defined here
collect2: ld returned 1 exit status
ubuntu@localhost:~/C-practice/Test$
-------------------------------------
這些資訊是沒加上-g不會出現的..XD
※ 編輯: BIAO (140.124.42.70), 05/03/2014 13:18:36