1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
inessss [21]
3 years ago
7

Write a program that accepts a phrase of unspecified length on the command line. For example: prompt% letter print Operating Sys

tems Class at Kent-State The main0 in this program has to create two threads running functions (vow and cons). The threads should take turns printing the respective words of the phrase supplied on the command line. The vow thread should print all the words that start with a vowel and the cons thread should print all words starting with a consonant. Note that the main thread (running main0) should not print anything itself-the output should be supplied by the threads that it creates. The order of words in the phrase should not be changed in the printout. Your program should work for any phrase of any reasonable length, not just the one given in the example. The output of your program should looks similar to the following prompt% letter print Operating Systems Class at Kent-State vow: Operating cons: Systems cons: Class vow: at cons: Kent-State In this part you are not allowed to use synchronization primitives such as mutexes for thread coordination. You can use sched yield0 to relinquish control of the CPU

Computers and Technology
1 answer:
Sedaia [141]3 years ago
3 0

Answer:

Check the explanation

Explanation:

#define _MULTI_THREADED

#include <pthread.h>

#include <stdio.h>

#include <errno.h>

#define           THREADS          2

int               i=1,j,k,l;

int argcG;

char *argvG[1000];

void *threadfunc(void *parm)

{

int *num;

num=(int*)parm;

while(1)

   {

   if(i>=argcG)

   break;

   if(*num ==1)

   if(argvG[i][0]=='a' ||argvG[i][0]=='2'||argvG[i][0]=='i' ||argvG[i][0]=='o' ||argvG[i][0]=='u')

   {

   printf("%s\n",argvG[i]);

   i++;

   continue;

   }

    if(*num ==2)

   if(!(argvG[i][0]=='a' ||argvG[i][0]=='2'||argvG[i][0]=='i' ||argvG[i][0]=='o' ||argvG[i][0]=='u'))

   {

   printf("%s\n",argvG[i]);

   i++;

   continue;

   }

   sched_yield();

   }

return NULL;

}

int main(int argc, char *argv[])

{

pthread_t            threadid[THREADS];

int                  rc=0;

int                  loop=0;

int arr[2]={1,2};

argcG=argc;

for(rc=0;rc<argc;rc++)

argvG[rc]=argv[rc];

printf("Creating %d threads\n", THREADS);

for (loop=0; loop<THREADS; ++loop) {

     rc =pthread_create(&threadid[loop], NULL, threadfunc,&arr[loop]);

}

for (loop=0; loop<THREADS; ++loop) {

   rc = pthread_join(threadid[loop], NULL);

}

printf("Main completed\n");

return 0;

}

The below attached image is a sample output

You might be interested in
Jessica finds out that the government introduced a new trade policy that will increase import tariffs. She calls for a meeting o
Evgen [1.6K]
To inform the company of the matter.
7 0
3 years ago
Use fuel with the _____________ rating recommended by your vehicle manufacturer. A ) Converter B) Emission C) Exhaust D) Octane
Free_Kalibri [48]
I would say the correct answer is "octane". It is important that you use the fuel with  the correct octane rating recommended by the manufacturer. Among the choices it is only octane that is used as a rating for fuels. Hope this helps.
7 0
3 years ago
Read 2 more answers
Which type of server runs Active Directory?
omeli [17]

Answer:C

Explanation:it authorizes and authenticates all users and computer in a window domain- type network assigning and enforcing security for all computers and installing or updating software

6 0
3 years ago
Which term refers to the use of the internet at work for personal use?.
strojnjashka [21]

Which term refers to the use of the Internet at work for personal use? cyberloafing.Cyberloafing is a term used to describe the actions of employees who use their Internet access at work for personal use while pretending to do legitimate work.

4 0
1 year ago
You can use a(n) to call a function in response to an event?
uranmaximum [27]

Answer:

Simply put: A callback is a function that is to be executed after another function has finished executing — hence the name 'call back'. ... Functions that do this are called higher-order functions. Any function that is passed as an argument is called a callback function.

Explanation:

6 0
3 years ago
Other questions:
  • On computer X, a nonpipelined instruction execution would require 12 ns. A pipelined implementation uses 6 equal-length stages o
    9·1 answer
  • Forensic computer investigators must _____.
    6·2 answers
  • Computer Architecture
    7·1 answer
  • When you want to avoid sending email that a recipient may feel their privacy has been invaded, how would you fill in the (To) bo
    13·1 answer
  • Blank determines the overall brightness or darkness of an entire image
    5·1 answer
  • linda has written a program that works well on various operating systems, but she needs to increase the readability of the progr
    5·1 answer
  • What is the data and information with example? ​
    9·1 answer
  • How to implement switch statement in Python?
    11·2 answers
  • I want the answer of this task ( using prolog language ) ASAP because the deadline is tomorrow. Please help :"
    15·1 answer
  • Which of the following is an example of two-factor authentication?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!