Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // threadtest.cc
- // Simple test case for the threads assignment.
- //
- // Create two threads, and have them context switch
- // back and forth between themselves by calling Thread::Yield,
- // to illustratethe inner workings of the thread system.
- //
- // Copyright (c) 1992-1993 The Regents of the University of California.
- // All rights reserved. See copyright.h for copyright notice and limitation
- // of liability and disclaimer of warranty provisions.
- #include "copyright.h"
- #include "system.h"
- #include "ctype.h"
- #include "string.h"
- //----------------------------------------------------------------------
- // SimpleThread
- // Loop 5 times, yielding the CPU to another ready thread
- // each iteration.
- //
- // "which" is simply a number identifying the thread, for debugging
- // purposes.
- //----------------------------------------------------------------------
- void InputCheck(int count);
- void Shout();
- void
- SimpleThread(int which)
- {
- int num;
- for (num = 0; num < 5; num++) {
- printf("*** thread %d looped %d times\n", which, num);
- currentThread->Yield();
- }
- }
- //----------------------------------------------------------------------
- // ThreadTest
- // Invoke a test routine.
- //----------------------------------------------------------------------
- void
- ThreadTest()
- {
- DEBUG('t', "Entering ThreadTest");
- Thread *t = new Thread("forked thread");
- //t->Fork(SimpleThread, 1);
- //SimpleThread(0);
- t->Fork(InputCheck, 0);
- //Shout();
- }
- void InputCheck(int count)
- {
- char input[100];
- printf("Enter input: ");
- fgets(input, sizeof(input), stdin);
- int length = strlen(input);
- length = length - 1;
- printf("Your input is: %s ", input);
- while (length == 0)
- {
- printf("Please re-enter a valid input: ");
- fgets(input, sizeof(input), stdin);
- length = strlen(input);
- length = length - 1;
- printf("Your input is: %s ", input);
- }
- bool decimal = false;
- bool number = false;
- bool negative = false;
- bool lastdec = false;
- if (input[0] == '-')
- {
- negative = true;
- count = 1;
- }
- for (count; count <= length; count++)
- {
- if(isdigit(input[count]) || input[count] == '.')
- {
- lastdec = false;
- if(isdigit(input[count]))
- {
- number = true;
- }
- if (input[count] == '.')
- {
- if (number == false)
- {
- printf("Character String \n \n");
- return;
- }
- if (count == length)
- {
- printf("Character String \n \n");
- return;
- }
- if (decimal == false)
- {
- decimal = true;
- lastdec = true;
- }
- else
- {
- printf("Character String \n \n");
- return;
- }
- }
- }
- if (isalpha(input[count]))
- {
- printf("Character String \n \n");
- return;
- }
- if (input[count] == ' ')
- {
- printf("Character String \n \n");
- return;
- }
- }
- if (decimal == false && number == true)
- {
- if (negative == false)
- {
- printf("Positive Integer \n \n");
- return;
- }
- else
- {
- printf("Negative Integer \n \n");
- return;
- }
- }
- if (decimal == true && number == true && lastdec == false)
- {
- if (negative == false)
- {
- printf("Positive Decimal \n \n");
- return;
- }
- else
- {
- printf("Negative Decimal \n \n");
- return;
- }
- }
- printf("Character String \n \n");
- return;
- }
- void Shout()
- {
- int T;
- int S;
- printf("How many threads would you like to shout? ");
- scanf("%d", &T);
- printf("How many times should they shout? ");
- scanf("%d", &S);
- printf("%i", T);
- printf("%i", S);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement