Seg-fault before main() with pthread

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Tue Nov 23 13:23:00 GMT 1999


> Any idea what's going wrong here?

Without actually testing anything, it looks like IO locks don't really
work, right now. In genops.c, we find

void
_IO_init (fp, flags)
     _IO_FILE *fp;
     int flags;
{
  ...
#ifdef _IO_MTSAFE_IO
  _IO_lock_init (*fp->_lock);
#endif
}

so the expectation clearly is that the new file has a member _lock
pointing to a valid _IO_lock_t (_lock itself is of type _IO_LOCK_T).

Now, this is called from

  __basic_file::__basic_file() 
  {
    _IO_init(this, 0);
    _IO_file_init(this); 
  }
  
where

  class __basic_file: public __c_file_type{...

__c_file_type is a POD, with no constructor, so _lock does not get
initialized. What *should* happen, imho, is

  class __basic_file: public __c_file_type{
    _IO_lock_t __cxx_lock;

  __basic_file::__basic_file() 
#ifdef _IO_MTSAFE_IO
    : _lock(&__cxx_lock)
#endif
  {
    _IO_init(this, 0);
    _IO_file_init(this); 
  }

Hope this helps,
Martin


More information about the Libstdc++ mailing list