현재 내 PC에서 실행되는 C++ 응용 프로그램에서 작업하고 있으며 BeagleBone Black에서 작동하도록하고 싶습니다. 이미 데비안 Wheezy가 설치되었습니다.응용 프로그램 boost :: thread가 BeagleBone에서 실행되는 ARM 용으로 컴파일 될 때 뮤텍스 잠금에 걸림 Black
내 PC (Intel Celeron, Debian Wheezy, v1.49.0-3.2)에서 BeagleBone Black (ARM Cortex A8, Debian Wheezy, boost v1.49.0-boost)으로 ELDK v5.3 및 qmake를 사용하여 크로스 컴파일하고 있습니다. 3.2).
모든 것이 작동해야하지만, boost :: thread가 생성되거나 응용 프로그램이 boost :: thread :: join()을 기다릴 때마다 내 응용 프로그램이 정지합니다 (__pthread_mutex_lock에 고정되어 있습니다). . 나는 지금 무슨 일이 일어나고 있는지 알고 싶다. 당신이 저를 높일 수 : 스레드 이러한 호출을 보호 할 수있는 몇 가지 팁이 있다면
(시도/캐치, 오류 상태 확인을 ...) 공유하시기 바랍니다 :)
감사합니다!
#include <stdio.h>
#include <boost/thread.hpp>
#define NB_THREADS 20
#define THREAD_LIFE_DURATION 5
int g_nb_thread = 0;
boost::thread * subRegisterThread(boost::thread * pthread)
{
printf("Register thread #%d %p created\n",
g_nb_thread++, pthread);
return pthread;
}
/////////////////// Sub dummy class
class sub_dummy_class
{
public:
boost::thread *mThread;
sub_dummy_class();
~sub_dummy_class();
void loop();
void start();
};
sub_dummy_class::sub_dummy_class()
{
mThread = NULL;
}
sub_dummy_class::~sub_dummy_class()
{
if(mThread)
{
mThread->join();
}
}
void sub_dummy_class::start()
{
mThread = subRegisterThread(new boost::thread(boost::bind(&sub_dummy_class::loop, this)));
}
void sub_dummy_class::loop()
{
int life_duration = THREAD_LIFE_DURATION;
while(life_duration > 0)
{
life_duration--;
printf("Got %d seconds to live !\n", life_duration);
usleep(1000000);
}
return;
}
////////////////////////// Dummy class
class dummy_class
{
public:
sub_dummy_class dummies[NB_THREADS];
dummy_class();
~dummy_class();
void start();
};
dummy_class::dummy_class()
{
}
dummy_class::~dummy_class()
{
}
void dummy_class::start()
{
for(int i = 0 ; i < NB_THREADS ; i++)
{
dummies[i].start();
}
}
int main(int argc, char* argv[])
{
printf("Starting program\n");
printf("Creating dummy class\n");
dummy_class *DC = new dummy_class();
printf("Starting dummy class\n");
DC->start();
printf("Deleting dummy class\n");
delete DC;
return 0;
}
: 여기
는 qmake에 명령을 실행할 때 애플리케이션의 정지 (GDB) 및 .PRO 파일 사용시 인쇄 역 추적이어서 BeagleBone 블랙상에서 실행될 때와 비슷한 방식으로 동결 작은 소스 코드
스택 추적 :
(gdb) bt
#0 __libc_do_syscall() at ../ports/sysdeps/unix/sysv/linux/arm/eabi/libc-do-syscall.S:44
#1 0xb6756f92 in __lll_lock_wait (futex=0x1881c, private=0) at ../ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c:47
#2 0xb675357a in __pthread_mutex_lock (mutex=0x1881c) at pthread_mutex_lock.c:61
#3 0xb68029dc in pthread_mutex_lock (mutex=<optimized out>) at forward.c:182
#4 0xb6991710 in lock (this=0xb69a2c68) at ./boost/smart_ptr/detail/spinlock_pt.hpp:41
#5 scoped_lock (pv=0x1f714, this=<synthetic pointer>) at ./boost/smart_ptr/detail/spinlock_pool.hpp:65
#6 atomic_increment (pw=0x1f714) at ./boost/smart_ptr/detail/sp_counted_base_spin.hpp:41
#7 add_ref_copy (this=0x1f710) at ./boost/smart_ptr/detail/sp_counted_base_spin.hpp:90
#8 shared_count (r=..., this=<optimized out>) at ./boost/smart_ptr/detail/shared_count.hpp:316
#9 shared_ptr (this=<optimized out>) at ./boost/smart_ptr/shared_ptr.hpp:164
#10 operator= (r=..., this=0x1f604) at ./boost/smart_ptr/shared_ptr.hpp:311
#11 boost::thread::start_thread (this=0x1f5e8) at libs/thread/src/pthread/thread.cpp:185
#12 0x0000cf7c in boost::thread::thread<boost::_bi::bind_t<void, boost::_mfi::mf0<void, sub_dummy_class>, boost::_bi::list1<boost::_bi::value<sub_dummy_class*> > > > (this=0x1f5e8, f=...)
at /opt/eldk-5.3/armv7a-hf/sysroots/armv7ahf-vfp-neon-linux-gnueabi/usr/include/boost/thread/detail/thread.hpp:205
#13 0x0000aa44 in sub_dummy_class::start (this=0x1cfdc) at main.cpp:51
#14 0x0000abc4 in dummy_class::start (this=0x1cf90) at main.cpp:96
#15 0x0000ac44 in main (argc=1, argv=0xbefff834) at main.cpp:109
편집 :
# .pro for test_boost
TEMPLATE = app
CONFIG =
QT -= qt webkit
TARGET = test_boost_ARM
QMAKE_LFLAGS += -Wl,-rpath ./
QMAKE_LFLAGS_RPATH =
HEADERS =
SOURCES = main.cpp
OTHER_FILES =
DESTDIR = .
# external libs
LIBS += -lboost_thread
0 : 여기 (++ qmake를 -spec 리눅스 armv7a-HF-g을)를 qmake를 명령에 사용하고있어 .PRO 파일입니다
이 두 매개 변수를 약간 테스트했습니다. NB_THREADS = 15 일 때마다 매번 괜찮은 것처럼 보이지만 16이되면 동결됩니다. THREAD_LIFE_DURATION은 (는) 프로그램 동작에 영향을 미치지 않습니다. 누군가가 무슨 일이 일어나는지 이해하는 데 도움이되기를 바랍니다.