#include <unistd.h>
#include <pthread.h>

#include <cstdlib>
#include <iostream>

class cpp_object {
public:
    cpp_object() {
    }
    virtual ~cpp_object() {
        std::cout << "In destructor" << std::endl;
    }
};

class thread_object {
public:
    thread_object() {
    }
    virtual ~thread_object() {
    }
    void start() {
        cpp_object obj;
        std::cout << "Waiting for cancel" << std::endl;
        sleep (10);
        std::cout << "Cancel wasn't called in time" << std::endl;
    }

};

extern "C" {
    void* test_routine( void* arg ) {
        thread_object* obj = (thread_object *) arg;
        obj->start();
        return NULL;
    }
}

int main(int argc, char *argv[]) {
    pthread_t thread_id;
	std::cout << "Welcome to the QNX Momentics IDE" << std::endl;

    thread_object obj;

    pthread_create( &thread_id, NULL, test_routine, &obj );
    sleep(15);
    pthread_cancel( thread_id );
    std::cout << "Canceled the thread" << std::endl;
    pthread_join( thread_id, NULL );
    std::cout << "Joined the thread" << std::endl;

	return EXIT_SUCCESS;
}
