|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
如下所示,调用pthread_join以后,报错,有大佬知道解决吗?/ b' j( M! ]9 I2 N1 n0 E
% \: w* R; J1 F; _- m) Xmsh />
/ o+ `! E1 K2 N3 X2 ]msh />2 u" O1 K7 _) l/ J( |
msh />5 D3 y2 {4 y% t: Q! c' n) [6 u7 L
msh />
- R4 M$ {) v# T( }' f A Pmsh />
2 K: `. }- s1 Z\ | /
& v" p- W' [! W S
1 O; h7 i+ j# A& H% _; W* uRT - Thread Operating System
9 d: q7 y/ z$ a/ | \ 4.1.0 build Jun 24 2022 16:22:28
; N9 D# i& s2 Z- U2006 - 2022 Copyright by RT-Thread team! w1 w9 L. j3 {, K
pthread_create success
/ J6 O; |* g# Q4 b) C: D4 ]. ai'm thread1 and i will detach myself!; K( Z3 }' k4 I: ]" T
posix thread 0+ K* |# T3 |2 l3 @, v/ Z2 h0 Q3 E
posix thread 1
3 M+ F( q: j5 @) f2 {posix thread 2
3 u! _: f' X4 S- @% O" t2 h: |- Qposix thread 3
$ O% E! a, u$ r- u4 `posix thread 42 s4 t+ V- O1 u; z- s$ T
thread1 exited!& [6 v; O7 a+ p2 x' `9 p
posix_thread_init exit1 I9 e# @0 N5 N- X- Q
msh />(small_mem != RT_NULL) assertion failed at function:rt_smem_free, line number:532
R1 z2 J9 S/ w" A: G; H#include <pthread.h>
$ E4 s8 s2 X4 S# A! |3 O#include <unistd.h>* }% w% F L! X' }! z4 R: ]4 {
#include <stdio.h>
/ x$ {4 ?7 x* \/ _: {6 Cstatic pthread_t tid1;
* e: r; @7 w5 h: n, v* `static void* thread1_entry(void *param)
- r. F7 @7 G2 K{9 ?+ y& F- T- h3 D; ]4 U% t0 m( F
printf("i'm thread1 and i will detach myself!\n"); t* D l4 @+ j Z
for(int i=0; i<5; i++)
8 m5 A6 y, M6 Z1 X s9 s{. v( A9 `- q4 J6 U+ a# {" Y; s- [
printf("posix thread %d\n", i);) L( z1 [5 Y$ s1 a
sleep(1);
/ o! a5 b8 C$ Z0 }( ~& t}
4 K9 f+ ]) A C- d: yprintf("thread1 exited!\n");
e6 f7 E- T. B* preturn NULL;& ]/ x( `( M) t) {3 v( \6 |
}
! E; ]8 A* K- O; E6 u: |/ Qstatic int posix_thread_init(void)
) I0 j3 R0 f2 o# @8 P{
0 _+ u$ r1 ~ S9 _. Pint result;
3 Q2 r3 ?! A4 V- g+ C! ]5 \result = pthread_create(&tid1, NULL, thread1_entry, NULL);
6 n g1 D6 \) u/ ^$ N% v3 S& Vif( result == 0 )/ ]% A$ D3 W- i' v! e( T+ B2 V
{
; R; ]: P. _3 v' Kprintf("pthread_create success\n");! b& W7 M8 Z3 E' y; ]3 E
}+ v( K3 f; b: n/ q2 u
else5 K8 K" L8 h. u+ u5 x' K0 d7 w
{7 t$ @' ~: N& o8 C& `" m2 A* @8 V
printf("pthread_create fail\n");
1 W( U: V8 {; v" {}
# ]5 Y. L2 @3 ?' P/ Npthread_join(tid1, NULL);' `% E+ q5 c5 p/ }0 ?. L
printf("posix_thread_init exit\n");4 b/ B: a+ y2 ?% V; Q
return 0;5 n( i+ Z, _2 o3 ` {
}
1 Q' d8 n& {7 J4 S/ V6 Q; t. fINIT_APP_EXPORT(posix_thread_init);
) z- L) d# B1 v; V* L, u) |6 v |
|