pThreads and globals var's - Raspberry Pi Forums
hi folks,
stop program blocking on getchar() i'v moved thread. updates global char typed in. seems update global when exits. snipet of code, not program i'm @ work , can't see it.
stop program blocking on getchar() i'v moved thread. updates global char typed in. seems update global when exits.
code: select all
static char input; void * keyboard (void *) { int exit = 0; while (!exit) { input = getchar(); if ("x" == input) { exit =1; } } } void main () { if ('1' == input) .... never if ('0'==input) else .....never if('x' ==input) break ... thread had stopped. }
ignore bit, heat induced idiocy
you declared input static, changes. might have it.
can declare variables volatile tell compiler read current value.
compiler can optimise putting variable register sections of code. statics supposed safe optimisation because value won't change. normal variables safe in scope (within function), memory locations set hardware (e.g. gpio inputs) fail read current status unless volatile specified (don't keep value in register).
keyboard thread running? need start it.
think meant have while loop in main() function.
written reach end of main , exit.
maybe help:
http://www.flipcode.com/archives/_kbhit_for_linux.shtml
you declared input static, changes. might have it.
can declare variables volatile tell compiler read current value.
compiler can optimise putting variable register sections of code. statics supposed safe optimisation because value won't change. normal variables safe in scope (within function), memory locations set hardware (e.g. gpio inputs) fail read current status unless volatile specified (don't keep value in register).
keyboard thread running? need start it.
think meant have while loop in main() function.
written reach end of main , exit.
maybe help:
http://www.flipcode.com/archives/_kbhit_for_linux.shtml
raspberrypi
Comments
Post a Comment