Secondly, boost::lexcial_cast does not guarantee thread safety - just as std::stringstream does not guarantee thread safety.
What do you mean by saying "thread-safety"? It is safe to use *distinct* std::stringstream objects in different threads, without synchnonization. It is not safe to use *shared* std::stringstream without synchronization. Thus, lexical_cast may be used in different threads without synchnonization, because every lexical_cast call uses its own local streambuf.
Yes, but if there is something specific you suggest I look for I would like input about that.
Do you use MSVC? If yes, please do as follows: 1) Go to menu Debug-->Exceptions... 2) In the exception tree open C++ exception branch and add "std::bad_cast" exception, then enable its check box. Now run your application. It will stop when lexical_cast throws exception, but before its handler is found (i.e. before the stack is unwound). Use "Call Stack" window to see what parameter was passed to lexical_cast.
The number of new threads that are generated is not predicable. I am using MSVS 2008. I can see every active thread in my application at any breakpoint. I can count how many threads are active and see what type of threads they are. I explicitly create N threads and count M threads where N is less than M. Immediately after I spawn my threads I halt execution and count how many are active and in what state they are in. At that point the only threads present are those I have spawned. I then let the app run and new threads appear which I did not explicitly create.
You see *all* the threads in the application - not only those you started with boost::thread(). You probably use some third-party libraries or COM, or some other facilities that launch threads implicitly. In "Threads" window you can see the type of every thread (like pthread, RPC thrread, Win32 thread etc.) and its call-stack - so you can figure-out where the thread comes from.