|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
如下所示,调用pthread_join以后,报错,有大佬知道解决吗?0 d3 G4 D/ r8 I6 @
6 Z1 G, p* R% X p% t& L+ g
msh />
; }$ _$ J" v( e+ H: \$ pmsh />5 T9 _# S" p% x5 I$ z6 b3 D
msh />) s5 P' S" {* p8 a+ e" r$ m
msh /> c( i( \+ w9 j: W3 n7 |
msh />! o0 U2 M2 ]7 k8 n8 _
\ | /
( m$ X/ y4 w4 N: [, B8 |7 h
& F- G) `8 m p1 w4 F' _RT - Thread Operating System- n& C# i, P3 {$ w5 o) Q
/ | \ 4.1.0 build Jun 24 2022 16:22:28
) g2 o3 I c7 U2006 - 2022 Copyright by RT-Thread team; u. i( x/ U E1 Z6 q) O
pthread_create success
# `$ k; y4 }! W0 {i'm thread1 and i will detach myself!
$ \$ }3 O' j8 t1 Kposix thread 06 K5 m' G, `1 m ~! D
posix thread 1* N6 X, I& D& ~
posix thread 2+ Y+ [3 [; p( V% l% H4 L: a8 O
posix thread 3( ~$ F) n0 ^, K8 i- z/ ?7 ?
posix thread 4; g+ y+ T. ^$ ?# ?8 B$ I
thread1 exited!
" w. n4 O- ?& t. \" L+ O, q! |- xposix_thread_init exit0 j+ |! h# l* m2 e, v$ h7 j
msh />(small_mem != RT_NULL) assertion failed at function:rt_smem_free, line number:532! @4 b7 ~" e* w& g- y9 t* l( s
#include <pthread.h>
8 _- T6 s. [2 L n8 m3 m#include <unistd.h>+ R J5 R: f' ?- m
#include <stdio.h>9 o- W. s- m, {) C4 i/ D. i9 z
static pthread_t tid1;
/ T' i4 D* t+ H+ n, o' T6 ^static void* thread1_entry(void *param)) \- Q8 @. Y+ a/ G$ U
{
v6 W/ Y3 m' m1 W+ Y3 rprintf("i'm thread1 and i will detach myself!\n");4 ^ N& x& a% d; X# i1 D1 ^# W2 X
for(int i=0; i<5; i++): }. l& J8 t0 E: t
{" A* G3 O6 l: e
printf("posix thread %d\n", i);* ^- ^ f- X1 S! F
sleep(1);
0 g' p# R! v3 t% E' w4 L* R4 r}
8 E z! k; t3 B& }printf("thread1 exited!\n"); p8 _+ P3 v/ w) }3 ]- B
return NULL;4 e5 @* ]0 H2 `& G2 b* y. v. A! K
}
5 g! r2 _! @8 C$ C' F) s5 _% X( Ustatic int posix_thread_init(void)9 P4 Z9 ^& @0 j' _
{
3 `8 T' U; m1 ^# {2 [, [int result;
5 y2 E% x8 f$ e. j' ]6 Presult = pthread_create(&tid1, NULL, thread1_entry, NULL);2 z P; v2 m+ T4 |* ~$ F$ m' x
if( result == 0 )! ?) O( f# T3 v4 R+ o
{
, n9 y) g0 X( i- S/ p* D7 Bprintf("pthread_create success\n");
+ P8 i% @8 H* _2 x; A}6 W1 J% A7 D; b' W) F
else' \; [! a( [6 h7 A3 V" o
{
: f. S& [/ j. p# Gprintf("pthread_create fail\n");; B/ g9 L. V$ K& a0 c- |* f* z6 b
}8 q/ y" P: ~) \* X* O9 [% K
pthread_join(tid1, NULL);
! Z9 t& W* Q# [7 O7 j3 [printf("posix_thread_init exit\n");2 |3 Z# w0 y" m1 P
return 0;
# d* V8 b- J2 {) f* U$ H' B) B/ F}
- W7 b" |7 j9 P! A( s5 H; r3 d/ S, xINIT_APP_EXPORT(posix_thread_init);
9 X5 R" P+ i' a0 f2 v3 f8 ` |
|