This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

stream.eof/AIX/pthread.h


gcc 4.1.1 on AIX 5.2
 
Somebody reported this before but there was no resolution
 
I have a program that loops over a stream until eof is set. 


#include <pthread.h>
#include <iostream>
#include <fstream>
 
 
 

std::string GetLine(std::ifstream *inp);
 
int main()
{
 
    std::ifstream response("/tmp/adcheck/shlog");
    if (!response.good())
    {
        std::cerr << "cannot read /tmp/adcheck/shlog" << std::endl;
        return 1;
    }
 
    while (response.good()&&!response.eof())
    {
        std::cout << "main " << response.eof() << "stream = " <<
&response << std::endl;
        std::string line = GetLine(&response);
        if(line.empty())
            continue;
        std::cout << line << std::endl;
    }
    std::cout << std::endl;
    return 0;
}
 
std::string GetLine(std::ifstream *inp)
{
    std::string result;
    while (true)
    {
        char ch;
        std::cout << "getline 1 " << inp->eof() << " stream " << inp <<
std::endl;
        inp->get(ch);
        std::cout << "getline 2 " << inp->eof() << " stream " << inp <<
std::endl;
        if (inp->eof() || ch == '\n')
            break;
        result += ch;
    }
    return result;
 
}

 
 
without pthread included this code works fine. the GetLine function ends
up with eof set, the main function sees eof and stops
with pthread included eof gets set in GetLine but when I pop back to
main eof is not set. When GetLIne is called again eof is set on entry!
ie the first cout<< in Getline shows eof is set, but the return to main
has it not set etc.

ends up looping like this
 
main 0stream = 0x2ff22b14 -> eof not set
getline 1 0 stream 0x2ff22b14 - > eof not set, read beyond end
getline 2 1 stream 0x2ff22b14 -> eof gets set
main 0stream = 0x2ff22b14 -> return to main - eof not set!
getline 1 1 stream 0x2ff22b14 -> enter getline eof is now set again 
getline 2 1 stream 0x2ff22b14 -> now we are stuck.....
main 0stream = 0x2ff22b14
getline 1 1 stream 0x2ff22b14
getline 2 1 stream 0x2ff22b14
main 0stream = 0x2ff22b14
getline 1 1 stream 0x2ff22b14
getline 2 1 stream 0x2ff22b14
main 0stream = 0x2ff22b14
getline 1 1 stream 0x2ff22b14
getline 2 1 stream 0x2ff22b14
main 0stream = 0x2ff22b14
 
behaves the same if GetLine uses reference rather than pointer.

 
In the previous report  there was one reply suggesting that he do -E and
look at the preprocessor output. I did that and nothing odd is happening

It feels like a thread local storage issue. THe stream has maybe put its
state in TLS and different calls are getting different TLS values
 


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