Original Post
Hello
I and a friend have written threads for the GBA, but we''ve
discovered that the std-lib of our compiler isn''t thread safe (actually, the std-lib is STLport but without thread-support since there are no P-threads or SGI-threads etc. for the GBA).
Therefore we have written a thread-safe allocator (it just uses our own versions of ''new'' and ''delete'' which disables thread-switching when the actual allocation of memory is done). We have tested oru ''new'' and ''delete'' a lot and know that they are thread-safe. But the STD-lib containers still crash even with our thread-safe allocator. A simple example:
Does anyone know how on earth the std-containers can be thread-unsafe even with thread-safe allocators ??? Are they coded in a really stupid way with static variables or what!, or are we doing something wrong?
Thanks for any help
class StupidThread : public Thread {
typedef list<B, SafeAlloc<B> > SList;
SafeAlloc<B> salloc; // our thread-safe allocator
SList slist;
public:
StupidThread(char *name = "Stupid thread") : Thread(name), salloc(), slist(salloc) {}
virtual void run() {
while (true) {
slist.push_back(B());
slist.pop_front();
} // Two threads like this running at once
} // ---> crash !
}; // One thread ---> OK (no crash)