This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/5347: implementation is not thread-safe on multi-processor machines



>Number:         5347
>Category:       libstdc++
>Synopsis:       implementation is not thread-safe on multi-processor machines
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 10 04:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     markus.breuer@materna.de
>Release:        up to current release
>Organization:
>Environment:
sun solaris 2.7/2.8 (multi-processor machine)
gcc 2.95.3 up to 3.0.x
>Description:
The libstdc++ implementation is not really thread-safe. 
Currently we allocate ostrstreams/ostrstreams with new and free them
immediatelly with delete. There's no access the the objects (except
new and delete), but the application sometimes crashes.

The main problem are static variables within streambuf (and perhaps other classes).
When instantiating an derived object (e.g. filestreambuf), this variables 
are accessed. On a single processor machine these accesses may be atomic (
depending on hardware), but an a real multi-processor environment they are not atomic.
When running our application on a single processor machine, there are no further 
problems, but on multi-processor there are unavoidable system crashes (core dumps).
>How-To-Repeat:
Compile and run the attached program on a (sun!?) multi-processor machine
>Fix:
To fix the problem the access to any global variable must be synchronized. Search
the libstdc++ for any static variable (streambuf/basic_string/etc) and use atomicity
to synchronize any access to it. Any access, read and write, must be synchronized.
The basic_string class uses atmicity to synchronize access to nulRep and Rep. But 
only the write access is synchronized. In a multi-processor environment the write access
of, for example an pointer, is not atomic. So its read-access must be guarded by
atomicity.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="HMSTestApp.cpp"; name="HMSTestApp.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="HMSTestApp.cpp"

Ly8gY21kOiBnKysgSE1TVGVzdEFwcC5jcHAgLWcgLXB0aHJlYWRzCgojaW5jbHVk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jpjb3V0IDw8
ICJMZWF2aW5nIHRocmVhZCAjIiA8PCBwdGhyZWFkX3NlbGYoKSA8PCAiLi4uIiA8PCBzdGQ6OmVu
ZGw7CiAgIAogICByZXR1cm4gMDsKfQoKCmludCBtYWluKCkKewogICBpbnQgY3RyOwogICAKICAg
c3RkOjpjb3V0IDw8ICJTdGFydHVwIC4uLiIgPDwgc3RkOjplbmRsOwogICAKICAgZm9yKCBjdHI9
MDsgY3RyIDwgbWF4X3RocmVhZF9jb3VudDsgY3RyKysgKQogICB7CiAgICAgIHB0aHJlYWRfdCBw
dCA9IHB0aHJlYWRfY3JlYXRlKCAmdGlkW2N0cl0sIE5VTEwsIHRocmVhZF9tYWluLCAwICk7CiAg
ICAgIHN0ZDo6Y291dCA8PCAidGhyZWFkICIgPDwgY3RyKzEgPDwgIiBzdGFydGVkIC4uLiIgPDwg
c3RkOjplbmRsOwogICB9CiAgIHdoaWxlICggcnVubmluZ1RocmVhZHMgKQogICAgICBzbGVlcCgg
MSApOyAgIAogICBzdGQ6OmNvdXQgPDwgIlNodXRkb3duIC4uLiIgPDwgc3RkOjplbmRsOyAgICAg
IAogICAKICAgcmV0dXJuIDA7Cn0KCg==


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]