does each thread has it's own memory space??

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

does each thread has it's own memory space??

Post by stinos »

Hi

I'm having this rather annoying problem with allocating memory, I suspect it has something to do with memory space (or whatever it's called).
here's some code:

Code: Select all

decl:

class TcpClientThread : public IThread
{
public:
      /**
        * Constructor.
        */
    TcpClientThread( const int ac_nRemoteAddress = gc_nDspAdress );

      /**
        * Destructor.
        */
    ~TcpClientThread();

      /**
        * Thread function.
        */
    void mp_Run();

      /**
        * The command queue.
        */
    typedef std&#58;&#58;deque<gt_Command> mt_CommandQueue;

      /**
        * The state queue.
        */
    typedef std&#58;&#58;deque<gt_eEventOp> mt_StateQueue;

&#91;omitted rest&#93;

private&#58;
  mt_StateQueue m_StateQ;
&#125;

impl&#58;&#58;

TcpClientThread&#58;&#58;TcpClientThread&#40; const int ac_nRemoteAddress &#41; &#58;
  m_StateQueue&#40; 0 &#41;
&#123;
&#125;

void TcpClientThread&#58;&#58;mp_Run&#40;&#41;
&#123;
  unsigned s = m_StateQ.size&#40;&#41;;

  char p&#91; 10 &#93;;
  sprintf&#40; p, "%u", s &#41;;
  PutMessage&#40; p &#41;; 

  mt_StateQueue GoodQ;
  s = GoodQ.size&#40;&#41;;
  sprintf&#40; p, "%u", s &#41;;
  PutMessage&#40; p &#41;; 
&#125;
the main() thread is kernel mode, and it has the TcpClientThread object, hence m_StateQueue gets allocated in kernel mode in the objects' ctor.

The TcpClientThread is started within main(), by calling some wrapper functions that start the mp_Run() function in a user mode thread (priority 0x18, stacksize 0x10000).
Both threads keep running during the program's lifetime.

PutMessage is like printf or so, what it prints is
78945631 for the size of m_StateQ (WTF?), while it prints 0 for GoodQ (OK!)
Also, trying to push_back something on the m_StateQ results in crashes most of the time, sometimes making slight modifications to the code crashes everything, sometimes it runs, sometimes it doesnt, etc..

Can anyone give me some insight on this? I use the same code on a lot of different architectures and os'ses so I thought it was fine, but it seems there is something different on PSP..



EDIT:

I also seem to have problems with the declaration of bool:

1>/cygdrive/c/pspdev/bin/../lib/gcc/psp/4.0.2/../../../../include/c++/4.0.2/bits/cpp_type_traits.h(222) : error: redefinition of 'struct std::__is_integer<int>'
1>/cygdrive/c/pspdev/bin/../lib/gcc/psp/4.0.2/../../../../include/c++/4.0.2/bits/cpp_type_traits.h(172) : error: previous definition of 'struct std::__is_integer<int>'

commenting out the definition at line 172 (the one for bool) solves the problem.

Another annoying problem remains though: if I put bool func(); in a class, it gives me

test.cpp(219) : error: no matching function for call to 'test::bFunc'
test.h(85) : note: candidates are: int test::bFunc

Any suggestions are welcome []-]
Noko
Posts: 23
Joined: Sat Sep 06, 2008 8:35 pm

Post by Noko »

Welcome to past, bitches!

You're initializing m_StateQueue, not m_StateQ. It is a mystery why it works.
Post Reply