List Info

Thread: - stdin read problem




- stdin read problem
user name
2008-04-25 09:38:56
Hi,

I've attached simple cpp program which demonstrates the
problem.
The program works fine from cmd.exe, but fails when started
from cygwin.

The program does the following:
- The main thread creates a helper thread which reads stdin
and prints
the data read.
- stdin is read via ReadFile() Win32 API function.
- At the end of the main function, the main thread calls
CloseHandle()
func for the stdin. It causes the ReadFile() function to
return, and
the helper thread to finish. From cmd the program works as
described.
- Under Cygwin  the program works differently. The helper
thread is
not finished, because it doesn't exit from the ReadFile()
func. The
main thread waits for the helper thread's completion during
1 sec,
then it calls TerminateThread() Win32 API func.

When I start the program from cmd, I see the following
output:
>read_stdin_example.exe
Stdin_Reader_Thread has been completed

When I start the program from Cygwin, I see:
$ ./read_stdin_example.exe
Stdin_Reader_Thread has NOT been completed. So, it will be
terminated.

I believe that this information would be enough to
investigate and fix
the problem.
If you need more information or have questions, feel free to
contact me.

Have a nice day!
~Alexey

  
Re: - stdin read problem
country flaguser name
Czech Republic
2008-04-25 09:55:11
Alexey Zakharov wrote:
> Hi,
> 
> I've attached simple cpp program which demonstrates the
problem.
> The program works fine from cmd.exe, but fails when
started from cygwin.
> 
> The program does the following:
> - The main thread creates a helper thread which reads
stdin and prints
> the data read.
> - stdin is read via ReadFile() Win32 API function.
> - At the end of the main function, the main thread
calls CloseHandle()
> func for the stdin. It causes the ReadFile() function
to return, and
> the helper thread to finish. From cmd the program works
as described.
> - Under Cygwin  the program works differently. The
helper thread is
> not finished, because it doesn't exit from the
ReadFile() func. The
> main thread waits for the helper thread's completion
during 1 sec,
> then it calls TerminateThread() Win32 API func.
> 
> When I start the program from cmd, I see the following
output:
>> read_stdin_example.exe
> Stdin_Reader_Thread has been completed
> 
> When I start the program from Cygwin, I see:
> $ ./read_stdin_example.exe
> Stdin_Reader_Thread has NOT been completed. So, it will
be terminated.
> 
> I believe that this information would be enough to
investigate and fix
> the problem.
> If you need more information or have questions, feel
free to contact me.
> 
> Have a nice day!
> ~Alexey
> 
Cross posting like this won't give you the kind of attention
you seek.

--
VH

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )