revisedessays logo
  • Our services
    • Write My Essay
    • Term Paper Services
    • Research Paper Services
    • Business Plan and Case Study
    • Dissertation and Capstone project
    • Nursing Help Services
    • Online Coursework Help
    • Proofreading and Editing
    • Finance and Accounting Help
    • Programming Help Services
  • About Us
    • How it works
    • Who are we
    • FAQ
  • Pricing
  • Contact Us
  • My account
  • Order now
Order Now
computer-engineering

Try switching the joins pthread_join(tid2, NULL); pthread_join(tid1, NULL); Do you see any difference? report if and why you do or do not see any difference

1 min read
Posted on 
March 31st, 2022
Home computer-engineering Try switching the joins pthread_join(tid2, NULL); pthread_join(tid1, NULL); Do you see any difference? report if and why you do or do not see any difference

Try switching the joins pthread_join(tid2, NULL); pthread_join(tid1, NULL); Do you see any difference? report if and why you do or do not see any difference in terms of the randomness in the result of the shared resource. In the inc_dec_resource() function, implement mutual exclusion (pthread_mutex_lock) to ensure that the result becomes 0 every time when you execute your program. Put your updated code in the report (highlighted) and show your screenshot of the execution by running the script three time using $ time ./shared_resource_mutex. Hint: Your loop is incrementing/decrementing the resource which should be protected by each thread while it is executing that portion. #include  #include  #define iterations 300000000 long long shared_resource = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // Thread function to modify shared resource void* inc_dec_resource(void* arg){ //get the pointer from main thread and dereference it to put the value in resource_value int resource_value = *(int *) arg; for(int i=0; i < iterations; i++){ shared_resource += resource_value; } pthread_exit(NULL); } int main(void){ // Thread 1 to increment shared resource pthread_t tid1, tid2; int value1 = 1; pthread_create(&tid1, NULL, inc_dec_resource, &value1); // Thread 2 to increment shared resource int value2 = -1; pthread_create(&tid2, NULL, inc_dec_resource, &value2); pthread_join(tid1, NULL); pthread_join(tid2, NULL); printf("Shared resource value: %lld\n", shared_resource); return 0; }

Order an Essay Now & Get These Features For Free:

Turnitin Report

Formatting

Title Page

Citation

Outline

Place an Order
Share
Tweet
Share
Tweet
Calculate the price
Pages (275 words)
$0.00
revisedessays
About Us
  • How it works
  • Who are we
  • FAQ
Location
High Falls Business Center 250 Mill Street Rochester, NY 14614
© 2023 revisedessays. All rights reserved.
revisedessays will be listed as ‘revisedessays’ on your bank statement.

WhatsApp us