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.

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. } 
snipet of code, not program i'm @ work , can't see it.

ignore bit, heat induced idiocy :oops:
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

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial