2013-08-07 32 views
3

我目前正在研究一個在我的PC上運行的C++應用程序,並且我希望使它在BeagleBone Black上工作已經安裝了Debian Wheezy。當編譯爲運行在BeagleBone黑色上的ARM編譯時,應用程序boost ::線程停留在互斥鎖上

我正在使用ELDK v5.3和qmake從我的PC(Intel Celeron,Debian Wheezy,boost v1.49.0-3.2)到BeagleBone Black(ARM Cortex A8,Debian Wheezy,boost v1.49.0- 3.2)。當一個boost :: thread被創建或應用程序正在等待一個boost :: thread :: join()時,我的應用程序凍結了(停留在一個__pthread_mutex_lock上) 。我只想了解發生了什麼。

如果你有一些技巧,可以幫助我保證這些調用的boost ::線程(try/catch語句,錯誤狀態檢查......),請分享:)

謝謝!!

下面是當在應用程序凍結(GDB)和pro文件執行qmake命令時所使用的黑色BeagleBone隨後印刷回溯執行以類似的方式沒有響應一個小的源代碼:

#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; 
} 

堆棧跟蹤:

(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文件我使用qmake命令(qmake的-spec Linux的armv7a-HF-克++):

# .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 

我測試了這兩個參數。當NB_THREADS = 15時,它似乎每次都很好,但當它等於16時,它經常凍結。 THREAD_LIFE_DURATION似乎對程序的行爲沒有任何影響。我希望它能幫助別人理解正在發生的事情。

回答

1

看起來升級到版本1.54可以解決這個問題。花了一些時間纔得到正確的軟件包,因爲Debian Wheezy的boost穩定版本是1.49,所以我不得不手動升級我的交叉編譯平臺。

該應用程序現在可以運行多達380個線程,沒有任何問題,這對我來說已經足夠了。