Question

Write a program which creates thread and passes argument to thread as CS203 in main program. The thread should be executed
thread should be executed first followed by the main program as follows:
operating system
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <pthread.h> #include <stdio.h> clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEA ? clang-7-pthread -lm -o main main.

#include <pthread.h>
#include <stdio.h>

// thread handler
void *handler(void *arg) {
    char *x = (char *)arg;
    printf("Welcome to the lab Sessions of %s\n", x);
    return NULL;
}

int main(int argc, char *argv[])
{
    char *arg = "CS203";
    pthread_t tid; /* the thread identifier */
    pthread_create(&tid, NULL, handler, (void *)arg);
    
    /// wait for the thread to complete
    pthread_join(tid, NULL);
    
    printf("End of the lab Session for %s.\n", arg);
}

**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
operating system Write a program which creates thread and passes argument to thread as "CS203" in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need some help on the following JAVA problem: Write a program in which the main thread...

    Need some help on the following JAVA problem: Write a program in which the main thread creates two threads named “Display” and “Daemon”. The first thread (Display) executes in an infinite loop and prints out its name and system time every 1 second until it is interrupted by the main thread. The second thread is a daemon thread that executes in an infinite loop and prints out its name. The main thread waits for a specific number of seconds n...

  • Write a program which creates a 2D array to store decimal values and passes that array...

    Write a program which creates a 2D array to store decimal values and passes that array to another function which sets each element of the array to a random value between 0.0 and 10.0.

  • You are required to write a C program on Unix/Linux in which the parent process creates...

    You are required to write a C program on Unix/Linux in which the parent process creates three child processes, lets them run concurrently, and waits for them to return and prints their exit status. The three child processes are assigned different tasks. Child one is to calculate and display the highest mark of a class of ten students for a unit. Child one is required to get the marks from the standard input (i.e. the keyboard). Child two is to...

  • Write a program where 3 separate threads simulate flipping a coin. The 3 threads should execute concurrently and each thread should do 1000 flips. Keep track of what is currently the record number of...

    Write a program where 3 separate threads simulate flipping a coin. The 3 threads should execute concurrently and each thread should do 1000 flips. Keep track of what is currently the record number of consecutive heads/tails (separately) and which thread produced that sequence. Every time a thread produces a longer sequence, display a message on the screen. Make sure other threads can’t interfere when updating the current record. N.B: This is a java object oriented program assignment.

  • 2) Write a complete program in which main creates two Integer arrayLists and then adds 1,...

    2) Write a complete program in which main creates two Integer arrayLists and then adds 1, 2, , 10 to the first ArrayList, and 21, 22, ^, 30 to the second ArrayList. main should call a method passing it the two ArrayLists. This method should create and return a third ArrayList, each slot of which contains the sum of the values in the corresponding slots of the first and second ArrayLists. On return to main, main should display the values...

  • write a function which takes a string argument and a character argument. It should return a...

    write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...

  • I want to write a C++ program which starts 2 threads. The first thread periodically generates...

    I want to write a C++ program which starts 2 threads. The first thread periodically generates a random number and adds it to the total. The second thread periodically generates a random number and subtracts it from the total. The main thread periodically monitors the value of the total. if the total exceeds the maximum value, the program terminates and alerts the user that the maximum has been exceeded. If the total undercuts the minimus value, the program terminates and...

  • Write a Python program that creates a class which represents a candidate in an election. The...

    Write a Python program that creates a class which represents a candidate in an election. The class must have the candidates first and last name, as well as the number of votes received as attributes. The class must also have a method that allows the user to set and get these attributes. Create a separate test module where instances of the class are created, and the methods are tested. Create instances of the class to represent 5 candidates in the...

  • Please help :) Problem 1: Complete separately Dr. Rocklino a) Write a program in which the...

    Please help :) Problem 1: Complete separately Dr. Rocklino a) Write a program in which the main method creates two arrays, each with 10 int slots. main initializes the first array to randomly generated integers. It then calls a method named copy, passing it the two arrays. Your copy method copies the contents of the first array to the second array. It then returns to main. main then displays the contents of both arrays. b) Write a program in which...

  • In C Programming Language, write a command line argument(s) program. The line should have program_name.exe input_file1.txt...

    In C Programming Language, write a command line argument(s) program. The line should have program_name.exe input_file1.txt “char_string”. The program should print an error message if there are not exactly three arguments on the line. input_file1.txt will have a word in it different than the “char_string”. The program will print on one line the char_string concatenated with input_file1.txt followed by the program name. Upon success print on new line, “Program finished!”

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT