Hi,

I had a query whether Windows multithreading API throw any Synchronization exception.
If I am sharing a STL string between threads and the string is not guarded,will there be any synchronization exception.

Another query is does STL container throw exceptions apart from memory violation
Thanks in advance :-)

Windows has no synchronisation exception, nor have I every seen an OS that did.

If you share any data between 2 threads, including an std::string without guarding access to the data then you risk corrupting the data by simultaneous access which is likely to be bad for program execution.

I think you should probably expect an stl::container to throw any standard exception I do not think it is specified what they do and don't throw, probably because of the possibility of it being platform dependent.

STL is not thread safe. Try to use mutexes to guard them.

Hello,
Thanks for your reply....
Apart from synchronization will there be any kind of exception thrown in case the STL string is shared among the threads..
Also i would like to know can ungaurded STL containers lead to crashing a system..

C++ is completely thread unaware, it has no concept of threads, threading or the posibility that it might be in use. That is because multi-tasking/multi-threading is highly platform dependent.

The STL will not throw any exceptions specifically related to multi-threading being used in a program.

Accessing any kind of data in an unguarded manor from multiple threads can lead to inexplicable behaviour, undefined behaviour and ultimately system crashes. The STL containers are no exception to this.

Hi,

I had a query whether Windows multithreading API throw any Synchronization exception.
If I am sharing a STL string between threads and the string is not guarded,will there be any synchronization exception.

Another query is does STL container throw exceptions apart from memory violation
Thanks in advance :-)

Hello,

Yes, Windows native threads throws synchronization exceptions.
STL containers are generally not thread safe and caution should be exercised when subjecting thread access to this objects. As a general rule when 2 or more threads are accessing a container for reading from them no guards need be placed. However when writing to these container objects are required then one must use mutexes or lock out that piece of code so that only one thread gets access to write else extremely potentially dangerous conditions can arise.

STL containers throw many other exceptions apart from memory violation like out of bounds exception, those thrown from destructors and copy constructors. Most of the exceptions mentioned in <exceptions> are supported by default by STL containers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.