Thursday, December 18, 2008

Symbian C++ sucks

Let's say you are developing on a Symbian phone. You are creating something more complex than a "Hello World" app so you need threads.

You create a RThread, and inside that thread you append things to a RArray (dynamic array) and then from the main thread you want to retrieve them.

NO! You can't! Accessing elements of a RArray from two different RThreads is not allow and it'll crash on you.

Ok you think, they just ported STL to Symbian, let's use a std::list, and NO! It'll crash even earlier.

So you are about to throw the phone across the window, but then you think, wait the also ported some POSIX things to Symbian, and try pthread and it suddenly works and you realize how simple things can be a nightmare when using weird tools/SDK, that's why Qt rocks it gives you almost all you want in a practical API, and when something is missing KDE adds the missing bit.

11 comments:

Anonymous said...

You mean, it crashes even if you synchronize access to the array ?
How did they implement this feature ?

Alex

Albert Astals Cid said...

Yeah i use a mutex i'm not THAT dumb :D

No idea how they did that but it's specified on their docs.

Blackpaw said...

Yes it is that ba d- I feel your pain.

A serious alternative is Python, its been ported to symbian and is actively maintained by symbian themselves. There's good access to the symbian api and you avoid all the horribleness of symbian C++

Blackpaw said...
This comment has been removed by the author.
Anonymous said...

So you are porting kdelibs to Qt for S60 now? ;-)

Anonymous said...

I think that Nokia knows the solution: http://pepper.troll.no/s60prereleases/

Anonymous said...

Probably too late now, but each created Symbian RThread, by default, uses it's own heap, so you will run into problems with accessing objects from one thread that were created in another. The solution is to make all new threads share the same heap - consult the API docs for details :)

Anonymous said...

First word of title is superfluous...

C++ sucks in most incarnations. Keeping to a sane subset of the jungle of possible suicide traps is a maniacs dance on the razors edge, only to be done by proper psychophats not considering the love of the future of humanity.

Anonymous said...

I know nothing about Symbian, and little about C++, but I disagree with your assertion that anything that is more complex than a Hello World requires threads. Threads are useful tools, but not something you need for every application on earth.

Albert Astals Cid said...

Some answers:

* No, i'm not porting kdelibs to S60, not enough time for that

* Thanks for the RThread sharing the heap tip, i wonder what's the usefulness of not sharing the heap by default

* No, C++ rocks if you use the correct tools (Qt/KDE for example)

* And yes, not something more complex than a Hello World, needs threads, but if you want to do asynchronous I/O it's almost a must.

Anonymous said...

You say "RThreads/RArray" doesn't work :-(
You say "RThreads/std::list" doesn't work :-(
You say "pthreads/std::list" works!
But what about "pthreads/RArray"? or "pthreads/RConnection" as in my case? It doesn't work again! and here the RThread tip isn't useful :-(