#include #include #include #include /* * faster_speller.c -- conceptual faster version of a serial speller */ int loaded = 0; void load_dict() { sleep(5); loaded = 1; } void *thread_load(void *data) { load_dict(); pthread_exit(NULL); } // phony suggest: return what is passed char *suggest(char *word) { return word; } int main ( int argc, char *argv[] ) { char line[128]; int retval; pthread_t tid; if ( argc > 1 && !strcmp(argv[1], "-s") ) { // serial/slow version load_dict(); } else { // create a thread to load dictionary retval = pthread_create(&tid, NULL, thread_load, NULL); } fprintf(stdout, "> "); fflush(stdout); while ( !loaded ) { usleep(100000); } while ( fgets(line, sizeof(line), stdin) ) { fprintf(stdout, "%s", suggest(line)); fprintf(stdout, "> "); } }