| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Keyboard thread |
Hello hugo,
On Apr 20 19:04 96, hugo landsman of 2:283/608.5 wrote:
MS>> how do you kill this thread?
hl> ungetc(27,stdin)?
:-), but not really? or?
first i will you the expected problems and then i will prove them:
a) the code for getch() MAY look like (and in fact the MS-C 6.0 getch()
code looks exactly this way. i looked into the ms-c lib)
getch()
{
if (ungetChar!=-1) return ungetCharArray[ungetChar--];
KbdCharIn(...,WAIT);
}
so, when thread 2 starts a getch, there is no unget char pending and getch
calls KbdCharIN and waits until a key is pressed...
when thread1 performs the unget, the following code is executed:
unget(char x)
{
if (spaceFree in ungetCharArray)
{
ungetCharArray[++ungetChar]=x;
return
}
}
b) another compiler vendor (VACPP) has similar code, but has made the code
thread-safe:
there is 1 Mutex-semaphore for the Kbd/Vio code.
getch()
{
requestLock(mux)
...
}
ungetch()
{
requestLock(mux)
...
}
so, in this case, thread2 is waiting for getch and thread1 has no chance
in ungetch a char...
ok, here's a sample app :
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
#include
#include
#include
#include
#define THREADSTACK 65536
//--------------------------------------------------------------------------
static void _Optlink input1(void *dummy)
{
printf("####### 1\n");
getch();
printf("####### 2\n");
}
//--------------------------------------------------------------------------
int main(int argc, char *argv[], char *envp[])
{
TID tid = (TID)_beginthread(input1,0, THREADSTACK, 0);
printf("----1------\n");
DosSleep(5000);
printf("----2------\n");
ungetch('a');
printf("----3------\n");
DosWaitThread(&tid, DCWW_WAIT);
printf("----4------\n");
}
icc -Fd+ -Sm -Ss+ -Si+ -Tl30 -Q+ -Wall+cls-gnr-lan-par-ppt-vft-inl-ppc-use-
-W3 -Gm+ xxx1.cpp
PS: to terminate the hanging app just press a key ....
WARPED!, Mario
--- Msgedsq/2 2.2e
* Origin: LC/32 Development Team-Vienna-Austria (2:310/14.11)SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809 @PATH: 310/14 1 24/999 888 396/1 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.