Boost logo

Boost Users :

Subject: Re: [Boost-users] seg fault on windows with Boost threads, istringstream, mingw
From: Kenny Riddile (kfriddile_at_[hidden])
Date: 2009-01-30 05:25:32


Tod Courtney wrote:
> I believe the problem is related to this code, which uses a
> istringstream to convert a string to a basic type (say a double):
>
> template <typename T>
> bool FromString(T &t,const std::string &s,
> std::ios_base &(*f)(std::ios_base &)=std::dec) {
> std::istringstream iss(s);
> return !(iss >> f >> t).fail();
> }

Somewhat off-topic, but couldn't you maybe use boost::lexical_cast to do
this?

> 1) Is there a multi-thread bug in the MinGW implementation istringstream?

If there is, I wouldn't call it a bug. The standard library makes no
guarantees about thread safety. For all you know a std::string
implementation could internally reference-count its buffers in a
non-thread-safe way.

> // wait until all threads to end
> for(int n=0;n<numThreads;n++) {
> worker[n]->join();
> delete worker[n];
> delete vec[n];
> }

Does moving the two delete calls outside of this loop so that no deletes
happen until all threads have finished fix the problem? If so, you
might consider using boost::ptr_vector to eliminate the explicit deletes
  and simplify some of the allocation code.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net