Almost forgot be sure to link with -lpthread.
Have Fun!
On Sun, Dec 29, 2013 at 4:18 PM, Daniel Metcalf <[email protected]> wrote:
> This was written in eclipse and verified on the beagle bone black running
> angstrom v2013.09.04
>
> /*
> * thread-test.cc
> *
> * Created on: Dec 29, 2013
> * Author: daniel
> */
> // thread example
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <pthread.h>
>
>
> void* foo(void* ptr)
> {
> for (int index=0; index < 30; index++)
> {
> printf("Current Count: %d\n", index);
> }
> usleep(1000);
> return 0;
> }
>
> void* bar(void* ptr)
> {
> int x = *(int*)ptr;
> for (int index=x; index < 60; index++)
> {
> printf("Current Count: %d\n", index);
> }
> usleep(1000);
> return 0;
> }
>
> int main()
> {
> int iret1 = 0;
> int iret2 = 0;
> int idata = 1;
>
> pthread_t first; // spawn new thread that calls foo()
> pthread_t second; // spawn new thread that calls bar(0)
>
> printf("main, foo and bar now execute concurrently...\n");
> iret1 = pthread_create( &first, NULL, foo, NULL);
> iret2 = pthread_create( &second, NULL, bar, (void*)&idata);
>
>
> // synchronize threads:
> pthread_join(first, NULL); // pauses until first finishes
> pthread_join(second, NULL); // pauses until second finishes
>
> printf("Thread 1 returns: %d\n",iret1);
> printf("Thread 2 returns: %d\n",iret2);
>
>
> printf("foo and bar completed.\n");
>
> return 0;
> }
>
> Have Fun!
>
>
> On Sat, Dec 28, 2013 at 9:56 PM, <[email protected]> wrote:
>
>> Hello everyone,
>>
>> I have been looking around and trying to find answers for my problem but
>> I have yet to run into a solution.
>>
>> So, I currently have the latest release of Angstrom for Beaglebone and I
>> have the latest g++ for it (4.5.4 I believe but I would prefer to have
>> 4.7.2). The kernel is 3.2.42 I believe.
>>
>> I have coded the threading example here:
>> http://www.cplusplus.com/reference/thread/thread/ and compiled with
>> combinations of -pthread, -lpthread, -std=c++0x, and std=c++11 but I always
>> get an error "pure virtual method called; terminate called without an
>> active exception; Aborted".
>>
>> I have looked around and it seems that can be fixed by g++ v4.7+ so I
>> decided to cross compile on my Ubuntu with g++ v4.7.2. I configured all the
>> necessary things required to cross compile on ARM and deploy on Beaglebone
>> but I either get the error of the one I mentioned or this "terminate called
>> after throwing an instance of 'std::system_error'; what():; Aborted".
>>
>> I have also looked around for that previous error but the suggested
>> solutions for that error did not help me at all.
>>
>> Has anyone gotten C++ and threading to work with Angstrom? If so, or if
>> you know a solution to my issue, could you point me to the right direction?
>>
>>
>> Thank you so much.
>>
>> --
>> For more options, visit http://beagleboard.org/discuss
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "BeagleBoard" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> --
> Dan Metcalf -- KB3UUN
>
--
Dan Metcalf -- KB3UUN
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.