Help with an error message


EvilDragon

Administrator
Staff member
Joined
Mar 4, 2003
Messages
29,986
Age
46
Location
Ingolstadt
I'm currently trying to port a remake of Bagman, but ran into an issue (probably a simple one):

That function:


 
 
    CNT &find_or_create()
    {
const ThreadId myid = me();
 
cs_start();
 
typename ContainerType::iterator rval = m_map.find(myid.p);
if (rval == m_map.end())
{
   // not found (first call to get() from this thread): create one
   // in thread safe mode (list is shared by all threads)
   
   
   std::pair<typename ContainerType::iterator, bool> success =
   m_map.insert(make_pair(myid.p,CNT()));
 
   // update size while in thread protected context
   
   m_size = m_map.size();
   
   rval = success.first;
 
}
 
cs_end();
 
return rval->second;
    }
 

spits out the following error:

Code:
 
src/sys/ThreadSafeContainer.h: In member function 'CNT& ThreadSafeContainer<CNT>::find_or_create()':
src/sys/ThreadSafeContainer.h:93:58: error: request for member 'p' in 'myid', which is of non-class type 'const ThreadId {aka const long unsigned int}'
  typename ContainerType::iterator rval = m_map.find(myid.p);
                                                          ^
src/sys/ThreadSafeContainer.h:101:34: error: request for member 'p' in 'myid', which is of non-class type 'const ThreadId {aka const long unsigned int}'
      m_map.insert(make_pair(myid.p,CNT()));
                                  ^
 
Hmmmm if ThreadId is indeed a long unsigned int, and myid is a ThreadId, then myid.p doesn't make much sense... Can you find the definition of ThreadId?
 
Yes, I'm using codeblocks, since it was a codeblocks project... Hmm, can I replace the compiler of codeblocks somehow or export it to a standard makefle?
 
Well, I can't really code C++, so trying to find what you need here.

A grep for it has the following results:

./sys/ThreadSafe.h:    typedef pthread_t ThreadId;

./sys/ThreadSafe.h:    inline ThreadId me() const { return pthread_self(); }

./sys/ThreadSafe.h:    bool is_me(const ThreadId id) const { return me().p == id.p; }

./sys/ThreadSafeContainer.h:    typedef typename ThreadSafe::ThreadId ThreadId;

./sys/ThreadSafeContainer.h: const ThreadId myid = me();
 
Hmmm. Ok, so ThreadId is in fact a pthread_t. Still, pthread_t is indeed a long unsigned int and has no "p" member. Those ThreadSafe and ThreadsafeContainer looks fishy to me?!
 
Well, I can send you the full source, if you want to take a look at it.

Standard SDL, so shoudln't be a big thing (except that you often need to fix .H to .h... windows users ;) )
 
Why not. It will be easier to fix the code. But I suppose there is no Linux version, only Windows one... So it will probably not be the only adaptation to do...
 
Well, it compiles for Windows, Amiga and NDS... so  thought it should compile on Linux as well ;)

Will send the code later. 
 
In pthread library for windows pthread_t is defined as:

typedef struct {
void * p; /* Pointer to actual object */
unsigned int x; /* Extra information - reuse count etc */
} ptw32_handle_t;

typedef ptw32_handle_t pthread_t;

 Also, the source code is probably here.

Edit:

You should probably use "pthread_equal(me, id)" to compare thread ID's instead of "me().p == id.p" (which works on windows).
 
Last edited by a moderator:
Yes, that's the sourcecode there :)

Your change leads to this error:

Code:
 
src/sys/ThreadSafeContainer.h:89:22: error: ISO C++ forbids declaration of 'pthread_equal' with no type [-fpermissive]
  const pthread_equal(me,id);
                      ^
src/sys/ThreadSafeContainer.h:89:25: error: 'id' was not declared in this scope
  const pthread_equal(me,id);
                         ^
src/sys/ThreadSafeContainer.h:89:27: error: expression list treated as compound expression in initializer [-fpermissive]
  const pthread_equal(me,id);
                           ^
src/sys/ThreadSafeContainer.h:93:53: error: 'myid' was not declared in this scope
  typename ContainerType::iterator rval = m_map.find(myid.p);
 
pthread ids are unique. There should be no reason you can't just replace all instances of "myid.p" with simply "myid".

ContainerType will also need to be changed from a vector<void*> to a vector<pthread_t> as well. I'm assuming it's a vector of pointers anyway, haven't looked at the code.

I'd like to find out who thought it was a good idea to have a different implementation of posix threads on Linux as on Windows and Mac. :(
 
I'd like to find out who thought it was a good idea to have a different implementation of posix threads on Linux as on Windows and Mac. :(
There's nothing wrong with having different implementations. The specification doesn't specify how pthread_t should be implemented. It's a bug in the program if it uses implementation specific details.
 
Would it simply be possible to put the Windows typedef sourcecode into the program code?

Or would the compiler complain then?
 
@EvilDragon: I have a working build. Do you want the source code modification or shall I publish myself (in that case, I'll take some time to put C4A support).
 
Nice :) You can publish it yourself, C4A would be awesome! I wanted to check though if I could recreate the graphics to beef it up a bit and maybe add different level as well.
 
Last edited by a moderator:
Ok. I'll publish than. C4A is created (I force Medium difficulty and 30000Pts for extra life), I have to create the marquee and send the conf file to @skeezix. I'll put the sources in the PND...

preview2.png
 
Last edited by a moderator:
Back
Top