Question: Write a program that has two threads. Make the first thread a simple loop that continuously increments a counter and prints a period (.) whenever

Write a program that has two threads. Make the first thread a simple loop that continuously increments a counter and prints a period (".") whenever the value of that counter is divisible by 10,000,000. Make the second thread repeatedly wait for the user to input a line of text and then print "Thank you for your input." On your system, does the first thread makes rapid progress? Does the second thread respond quickly?

(Code in C language)

//I have my code here but nothing shows up after I ran the compiled executable files

// I don't see why the print message won't show up in a long time, longer than I expected

// the ideal result would be seeing a bunch of "dots" on the screen and a prompted message

// for User to enter something.

// My Code:

#include

#include

#include "thread.h"

static void one(int n);

static void second(int n);

static thread_t thread1;

static thread_t thread2;

int main(int argc, char**argv) {

int i = 1;

thread_create(&thread1, &one, i);

int j = 2;

thread_create(&thread2, &two, j);

}

void one(int n) {

int i = 0;

while(1) {

i ++;

if(i % 10000000 == 0) {

printf(".");

} }

}

void second(int n) {

char str[256];

while(1) {

printf("Enter something: ");

scanf("%s", str);

if((int)strlen(str) != 0) {

printf("Thank you for your input! ");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!