greetings,
g++ --version ... egcs-2.90.29 980515 (egcs-1.0.3 release)
redhat 5.2 kernel version 2.0.36
i have the following code (test.cpp), compiled with ...
g++ -g -static -D_MIT_POSIX_THREADS -Dlinux test.cpp -lpthread
if you run it a few times it'll cause a seg fault.
after looking thru /usr/include/libio.h i spotted the #define _IO_MTSAFE_IO
however defining this at the top of the code (as i've done below) makes
no difference.
anyone got any clues?
thanks,
c
ps let me know if you need more info.
#define _IO_MTSAFE_IO
#include <unistd.h>
#include <pthread.h>
#include <sched.h>
#include <assert.h>
#include <iostream.h>
void*
run(void *i)
{
cerr << "ourthread::run" << endl;
for (int i = 0; i < 100; ++i)
{
cerr << " thread i=" << i << endl << flush;
int m_last_error = sched_yield();
assert(m_last_error == 0 && "failed to yield");
}
return 0;
intQuote:}
main()
{
# ifdef _IO_MTSAFE_IO
cerr << "thread safe io in place !!??" << endl;
# else
cerr << "uhoh !!!???" << endl;
# endif
cerr << "start" << endl;
pthread_t m_thread;
int m_last_error = pthread_create(&m_thread,
0,
run, (void *)0);
assert(m_last_error == 0 && "failed for some reason");
for (int i = 0; i < 100; ++i)
{
cerr << "main i=" << i << endl << flush;
m_last_error = sched_yield();
assert(m_last_error == 0 && "failed to yield");
}
void **ret;
m_last_error = pthread_join(m_thread, ret);
assert(m_last_error == 0 && "something really BAD happened");
cerr << "done" << endl;
return 0;
Quote:}