To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2224
2223  |  2225
Subject: 
thread class for legOS
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 18 Jan 2002 12:40:45 GMT
Viewed: 
1635 times
  
I write a Thread class for LegOs with a simple interface like in Java or
CommonC++. I'm using
LegOs 0.2.4.
Below are my work till yet. The problem is in the Method Start(). The
line is marked with !!.
The error message is at the end of the file.
I havn't any idea how to cast a (Thread::*) to (*).
Can anyone help me, please?

Marc Kösling


/***** Thread.h **********************************/
  #include <tm.h>
  #include <unistd.h>

  class Thread  {
  public:
        Thread(priority_t p_Prio = PRIO_NORMAL, size_t p_Stack =
DEFAULT_STACK_SIZE);
        virtual ~Thread();

        virtual void Run() = 0;
        void Stop();
        void Start();

  protected:
        size_t m_Stack;
        priority_t m_Prio;
        int m_Pid;

  private:
        int runWrapper(int, char ** dummy);
  };

/**** Thread.cpp **********************************/

  Thread::Thread(priority_t p_Prio, size_t p_Stack) {
        m_Prio = p_Prio;
        m_Stack = p_Stack;
        m_Pid = 0;
  }

  Thread::~Thread() {
        Stop();
  }

  void Thread::Start() {
        if(m_Pid == 0)
!!              m_Pid = execi(&Thread::runWrapper, 0, (char**)NULL,
m_Prio, m_Stack);
  }

  void Thread::Stop() {
        if(m_Pid != 0)
        {
                kill(m_Pid);
                m_Pid = 0;
        }
  }

int Thread::runWrapper(int, char ** dummy) {
  Run();
  return 0;
}

void Thread::Run() {}

/usr/local/crossgcc/h8300-hitachi-hms/bin/h8300-hitachi-hms-g++ -DCXX
-O2 -fno-builtin
-fomit-frame-pointer -Wall -I/usr/local/legOS/include  -
I/usr/local/legOS/include/lnp -I. -I../../boot/  -c
Thread.cpp -o Thread.o
Thread.cpp: In method `void Thread::Start()':
Thread.cpp:26: converting from `int (Thread::*)(int, char **)' to `int
(*)(int, char **)'
make: *** [Thread.o] Error 1



Message has 1 Reply:
  Re: thread class for legOS
 
(...) IRC, every method in C++ has an implicit parameter wich is the object itself; that's why you can't cast it. Try the following (does someone have a nicer solution?): Put runWrapper() outside the class: int runWrapper(int, char **th) { (...) (22 years ago, 18-Jan-02, to lugnet.robotics.rcx.legos)

8 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR