delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/04/25/10:39:24

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <216a31560804250738h5284d4c9i415ae131a79e4318@mail.gmail.com>
Date: Fri, 25 Apr 2008 18:38:56 +0400
From: "Alexey Zakharov" <alexey DOT a DOT zakharov AT gmail DOT com>
To: cygwin AT cygwin DOT com, cygwin-talk AT cygwin DOT com, cygwin-developers AT cygwin DOT com
Subject: - stdin read problem
Cc: alexey DOT zakharov AT intel DOT com
In-Reply-To: <216a31560804250726r55620c94tc0ec27cbb640dd57@mail.gmail.com>
MIME-Version: 1.0
References: <216a31560804250726r55620c94tc0ec27cbb640dd57 AT mail DOT gmail DOT com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

------=_Part_4910_22877414.1209134336569
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

------=_Part_4910_22877414.1209134336569
Content-Type: text/plain; name=main.cpp
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ffguwmaz
Content-Disposition: attachment; filename=main.cpp

DQojaW5jbHVkZSA8c3RkaW8uaD4NCiNpbmNsdWRlIDx3aW5kb3dzLmg+DQoN
CiNkZWZpbmUgTVlfQlVGX1NJWkUgMTAyNA0KDQpEV09SRCBXSU5BUEkgcmVh
ZF9zdGRpbihMUFZPSUQgbHBQYXJhbWV0ZXIpDQp7DQogICAgQk9PTCBiUmVz
dWx0ID0gRkFMU0U7DQogICAgY2hhciBzekJ1ZltNWV9CVUZfU0laRV0gPSAi
IjsNCiAgICBpbnQgbkluZGV4ID0gMDsNCiAgICBEV09SRCBuTnVtT2ZCeXRl
c1JlYWQgPSAwOw0KDQogICAgSEFORExFIGhTdGRpbiA9IEdldFN0ZEhhbmRs
ZShTVERfSU5QVVRfSEFORExFKTsNCiAgICBpZiAoaFN0ZGluID09IE5VTEwg
fHwgaFN0ZGluID09IElOVkFMSURfSEFORExFX1ZBTFVFKQ0KICAgIHsNCiAg
ICAgICAgcHJpbnRmKCJHZXRTdGRIYW5kbGUgZmFpbGVkIGZvciBTVERfSU5Q
VVRfSEFORExFXG4iKTsNCiAgICAgICAgZXhpdCgyKTsNCiAgICB9DQoNCiAg
ICBuSW5kZXggPSAwOw0KICAgIGZvciAoOzspDQogICAgew0KICAgICAgICBu
TnVtT2ZCeXRlc1JlYWQgPSAwOw0KICAgICAgICBzekJ1ZltuSW5kZXhdID0g
J1wwJzsNCiAgICAgICAgYlJlc3VsdCA9IFJlYWRGaWxlKGhTdGRpbiwgJnN6
QnVmW25JbmRleF0sIDEsICZuTnVtT2ZCeXRlc1JlYWQsIE5VTEwpOw0KDQog
ICAgICAgIGlmIChiUmVzdWx0KQ0KICAgICAgICB7DQogICAgICAgICAgICBp
ZiAobk51bU9mQnl0ZXNSZWFkID09IDApDQogICAgICAgICAgICB7DQogICAg
ICAgICAgICAgICAgLy8gRW5kIG9mIHRoZSBmaWxlIHdhcyByZWFjaGVkDQoN
CiAgICAgICAgICAgICAgICAvLyBQcmludCB0aGUgZGF0YSByZWFkIGlmIHRo
ZXkgZXhpc3QNCiAgICAgICAgICAgICAgICBpZiAobkluZGV4ID4gMCkNCiAg
ICAgICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgICAgIHByaW50Zigi
SW5wdXQgZGF0YSA9IFwiJXNcIlxuIiwgc3pCdWYpOw0KICAgICAgICAgICAg
ICAgIH0NCg0KICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAg
fQ0KDQogICAgICAgICAgICBpZiAoIChzekJ1ZltuSW5kZXhdID09ICdcbicp
IHx8IChuSW5kZXggPT0gTVlfQlVGX1NJWkUgLSAxKSApDQogICAgICAgICAg
ICB7DQogICAgICAgICAgICAgICAgLy8gRW5kIG9mIHRoZSBpbnB1dCBoYXMg
YmVlbiBkZXRlY3RlZA0KICAgICAgICAgICAgICAgIC8vIFByaW50IHRoZSBp
bnB1dCBkYXRhDQogICAgICAgICAgICAgICAgcHJpbnRmKCJJbnB1dCBkYXRh
ID0gXCIlc1wiXG4iLCBzekJ1Zik7DQoNCiAgICAgICAgICAgICAgICAvLyBS
ZXNldCB0aGUgaW5kZXggYmFjayB0byB0aGUgYmVnaW5uaW5nIG9mIHRoZSBp
bnB1dCBidWZmZXINCiAgICAgICAgICAgICAgICBuSW5kZXggPSAwOw0KICAg
ICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgew0K
ICAgICAgICAgICAgICAgIC8vIEluY3JlbWVudCB0aGUgaW5kZXggYW5kIGNv
bnRpbnVlIHRoZSBy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VRfSEFORExFKSk7DQogICAgaWYgKFdhaXRGb3JT
aW5nbGVPYmplY3QoaFN0ZGluUmVhZGVyVGhyZWFkLCAxMDAwKSAhPSBXQUlU
X09CSkVDVF8wKQ0KICAgIHsNCiAgICAgICAgcHJpbnRmKCJTdGRpbl9SZWFk
ZXJfVGhyZWFkIGhhcyBOT1QgYmVlbiBjb21wbGV0ZWQuIFNvLCBpdCB3aWxs
IGJlIHRlcm1pbmF0ZWQuXG4iKTsNCiAgICAgICAgVGVybWluYXRlVGhyZWFk
KGhTdGRpblJlYWRlclRocmVhZCwgMSk7DQogICAgfQ0KICAgIGVsc2UNCiAg
ICB7DQogICAgICAgIHByaW50ZigiU3RkaW5fUmVhZGVyX1RocmVhZCBoYXMg
YmVlbiBjb21wbGV0ZWRcbiIpOw0KICAgIH0NCiAgICBDbG9zZUhhbmRsZSho
U3RkaW5SZWFkZXJUaHJlYWQpOw0KDQogICAgcmV0dXJuIDA7DQp9IC8vIG1h
aW4NCg==


------=_Part_4910_22877414.1209134336569
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_Part_4910_22877414.1209134336569--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019