#include <stdlib.h>
#include <stdio.h>
#include "uthread.h"
#include "uthread_mutex_cond.h"
uthread_t t0, t1, t2;
void randomStall() {
int i, r = random() >> 16;
while (i++<r);
}
void* p0(void* v) {
randomStall();
printf("zero\n");
return NULL;
}
void* p1(void* v) {
randomStall();
printf("one\n");
return NULL;
}
void* p2(void* v) {
randomStall();
printf("two\n");
return NULL;
}
int main(int arg, char** arv) {
uthread_init(4);
t0 = uthread_create(p0, NULL);
t1 = uthread_create(p1, NULL);
t2 = uthread_create(p2, NULL);
randomStall();
uthread_join (t0, NULL);
uthread_join (t1, NULL);
uthread_join (t2, NULL);
printf("three\n");
printf("------\n");
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Modify the program q4.c to use a mutex and one or more condition variables to order the threads to produce the same output as your solution to the first question, where you ordered threads using uthread_join. Your solution must use condition variables to
Modify the program q1.c by adding calls to uthread_join (and making no other changes) so that it always prints the lines “zero” to “three” in order; i.e., its output must always be the following. q1.c code as below: #include <stdlib.h> #include <stdio.h> #include "uthread.h" uthread_t t0, t1, t2; void randomStall() { int i, r = random() >> 16; while (i++<r); } void* p0(void* v) { randomStall(); printf("zero\n"); return NULL; } void* p1(void* v) { randomStall(); printf("one\n"); return NULL; } void*...
1. (50 pts) Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string ('A'<>'Z', 'B'<->'Y', 'C''X', etc). You should divide this conversion task among the n threads as evenly as possible, Print out the...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...
If you already answer this question, please skip, thanks C Programming. Fill in ... This program will be called with one command line argument that contains a string followed by an asterisk and an integer. Print out the string as many time as indicated by the integer. For example, when called as prog Hi*3, you print HiHiHi. Hint: Look for the '*' starting from the back of the string. len = strlen(arg) gives you the string length. When you have...
I'm having trouble getting my program to output What is your first name? damion what is your last name? anderson damion, Your first name is 6 characters Your last name, anderson, is 8 characters Your name in reverse is: noimad nosredna This is my code so far: #include <stdlib.h> #include <stdio.h> void sizeOfName(char** name); void printSizeOfName(int *first, int *last, char** name); void reverseString(int *first, int *last, char** name); int main() { char** name; name = (char**)malloc(2*sizeof(char*)); name[0] = (char*)malloc(100*sizeof(char)); name[1]...
OPERATING SYSTWM
Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...
My C program is supposed to make a random key the same length of
clear_text string and then use the random key to encrypt
clear_text, but I can’t get it to work.
A wΝΗ 1 #include <stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 char* make_rand_key(int length, char* key); 5 void encrypt(); 7- int main() { 8 encrypt(); 9 } 10 char* make_rand_key(int length, char* key){ int range=78; int max=48; char c='a'; int i; 'srand(time(NULL)); for(i=0;i<length;i++){ C=rand()%range_max; key[i]=c; key[i]='\0'; return key; 23...
1) Compile thread2.c (remember the -lpthread flag). Run it numerous times, and notice the output usually differs. a) Why is the variable myglobal usually not 40? Be specific, be precise. b) In what special case would myglobal be 40? Be specific, be precise. #include <pthread.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <fcntl.h> /* Purpose: Use 2 threads to increment myglobal exactly 40 times in total. Compile: using -pthread option */ int myglobal = 0; void *thread_function(void *arg) { ...
QUESTION 1 In order to print the members of structures in the array, what will be the contents of blanks in the printf statement of the code snippet given below? #include <stdio.h> struct virus { char signature[25]; char status[20]; } v[2] = { "Yankee Doodle", "Deadly", "Dark Avenger", "Killer" } ; void main( ) { for (int i = 0; i < 2; i++) printf( "\n%s %s", _______________ , _____________ ); } A. signature, status B. v.signature,...
Compile and run the deadlockFree.c program below and report if this program does go into deadlock or not. Modify this deadlockFree.c program so that you change the lock/unlock order of the mutexes. Experiment with the order of locks (and maybe extend the number of loop iterations) until you find a scenario where you can demonstrate deadlock. //Program: deadlockFree.c A simple threaded program to demonstrate the deadlock condition.Two threads are used to wait on two MUTEXES. Careful ordering of locks should...