C++11 and threading on BeagleBone Black

2,332 views
Skip to first unread message

J Adam Crain

unread,
Jul 31, 2013, 9:23:19 AM7/31/13
to automat...@googlegroups.com
All,

I'm starting a new thread to focus on the threading issues with BBB.

I keep getting the same results as Cornel and others, pure virtual method calls.

I decided to test the most basic C++11 threading program:

-----------------------------------------
#include <iostream>
#include <thread>

using namespace std;

int main(int argc, char** argv)
{
  cout << "hello world" << endl;
  thread t([](){ cout << "hello from thread!" << endl; });
  t.join();
  return 0;
}
-----------------------------------------

On Unbuntu 13 w/ G++ 4.7.3:

> g++ --std=c++11 Test.cpp -lpthread
> ./a.out 
hello world
hello from thread!
>

On BeagleBone black:

root@beaglebone:~/test# ./a.out 
hello world
pure virtual method called
terminate called without an active exception
Aborted
root@beaglebone:~/test#

So, we have to solve this basic issue before we can proceed. Time to start hitting the BBB mailing lists!

-Adam

J Adam Crain

unread,
Jul 31, 2013, 10:14:01 AM7/31/13
to automat...@googlegroups.com
Ok, I have an answer. It involves some deep, dark black magic that I will never understand:


Add the following pre-processor declarations to the build:

-D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8

This fixed the issue with the example program.  To do this for opendnp3, add this stuff to the configure step, i.e.:

> ./configure CXXFLAGS="--std=c++11 -pthread -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8"

I am rebuilding opendnp3 in the background this morning on the BBB. I'll report when I have the tests passing.

-Adam

J Adam Crain

unread,
Jul 31, 2013, 11:21:35 AM7/31/13
to automat...@googlegroups.com
Kazaa!

-----------------------
root@beaglebone:~/dnp3# ./dnp3test --show_progress

0%   10   20   30   40   50   60   70   80   90   100%
|----|----|----|----|----|----|----|----|----|----|
Running 461 test cases...
****************************************************** No errors detected
------------------------------
root@beaglebone:~/dnp3/cpp/demos/outstation# ./outstationdemo
Server state: CLOSED
Wed Jul 31 15:18:30.855664 - INFO - tcpserver.outstation.outstation - StackState: COMMS_DOWN
Server state: OPENING
outstation state: COMMS_DOWN
Enter something to increment a counter or type exit
-------------------------------

-Adam

J Adam Crain

unread,
Jul 31, 2013, 11:32:56 AM7/31/13
to automat...@googlegroups.com
All in all, a very nice little hobby board. I am impressed with the out-of-the-box functionality.

It has some impressive I/O capabilities and the realtime MCU functionality looks interesting too.

Daniel and Cornel:

Please let me know if those pre-processor defines resolve your issues.

-Adam

Daniel

unread,
Aug 1, 2013, 2:55:47 AM8/1/13
to automat...@googlegroups.com
Hi Adam,

Thanks for the update. I haven't had time recently to play with the BBB debugging. I will do a test over the weekend and post my results.

Thanks Adam and Cornel!

Regards

Cornel Verster

unread,
Aug 1, 2013, 8:41:05 AM8/1/13
to automat...@googlegroups.com
Tested it and my code works :)

Thanks so much for the help Adam, it is greatly appreciated!

Cornel
Reply all
Reply to author
Forward
0 new messages