作者abcd991276 (QQ)
看板C_and_CPP
标题[问题] 为什麽会印两次child
时间Thu Feb 17 21:10:15 2022
https://i.imgur.com/nIqiVdt.jpg
我把X设成1
他会印出
parent: begin
parent: end
child
child
X设成0的时候
会印出
parent: begin
child
Parent: end
很好奇为什麽parent先结束
child会印两次
----
Sent from
BePTT
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.174.95.189 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1645103417.A.BB2.html
1F:推 lc85301: 我没办法重现,只会印一次 child 02/17 22:59
2F:推 kingofsdtw: 贴图我懒的看程式 02/22 02:23
3F:→ kingofsdtw: 至少弄个复制贴上吧 02/22 02:23
4F:→ TianBonBon: 这什麽环境和编译器? 02/22 13:18
5F:→ abcd991276: 在win 10的Ubuntu子系统 我用Gcc 编译的 02/22 19:19
6F:推 Domos: 改成children就正确了 02/22 20:58
7F:→ lc85301: 楼上笑死XDD 02/22 23:51
8F:→ sarafciel: 应该thread被绿了才会多一个child出来 请左转男女版(X 02/23 09:36
9F:→ TianBonBon: 传给pthread_create()的c应该是要&c吧? 没出SEGV反而 02/23 12:42
10F:→ TianBonBon: 恐怖 02/23 12:42
11F:→ Dracarys: 1. 使用未初始化变数 c -> undefined behavior,大概少 02/23 14:17
12F:→ Dracarys: 打& 02/23 14:17
13F:→ Dracarys: 2. ld.lld: error: undefined symbol: Pthread_create 02/23 14:17
14F:→ Dracarys: ,libpthread.so只有pthread_create。 02/23 14:17
15F:→ Dracarys: 3. X设1,没join大概率child不会印 02/23 14:17
16F:嘘 Dracarys: Warning开多一点,辅以ubsan、tsan怎麽可能没发现 02/23 14:22
18F:推 n1canhelpu: 0.0 &呢? 03/02 07:50