Basic Thread Functions - Advanced Unix Programming - Lecture Slides, Slides of Computer Programming

Some concept of Advanced Unix Programming are Address Structure, Basic Thread Functions, Client-Server Design, Network Programming, Signals and Thread, Thread-Specific Data, Unix File System, Reliable Communication. Main points of this lecture are: Basic Thread Functions, Thread Functions, Thread-Specific Data, Mutual Exclusion, Conditional Variables, Thread Attributes, System Lacks Resources, Invalid Attribute, Appropriate Permission, Pthread Functions

Typology: Slides

2012/2013

Uploaded on 04/29/2013

parmita
parmita 🇮🇳

4.7

(17)

183 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Week 11 Topics
Threads
Basic thread functions
Some more thread functions
Thread-specific data
Mutual exclusion
Conditional variables
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Basic Thread Functions - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Week 11 Topics

  • Threads
    • Basic thread functions
    • Some more thread functions
    • Thread-specific data
    • Mutual exclusion
    • Conditional variables

Basic thread functions

  • Thread creation int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void (start_routine)(void *), void * arg) - Thread attributes (stack size, scheduling policy) can be modified - Use NULL for default - Returns 0 if successful, and an error number if it fails - EAGAIN: System lacks resources - EINVAL: Invalid attribute - EPERM: Caller does not have appropriate permission - Pthread functions return error values - They do not set errno - New thread executes the function given by start_routine - arg is the argument to this function - The thread ID is stored in *thread

Some more thread functions

  • pthread_t pthread_self(void)
    • Get ID of the current thread
  • void pthread_exit(void *value_ptr)
    • Exits a thread
  • int pthread_detach(pthread_t tid)
    • Make a thread detachable
      • pthread_join will not be called on this thread

Client-server

  • Implementing a concurrent server using

pthreads

  • example3.c and old.client. c
  • What happens if you uncomment the sleep

statements in example3.c?

  • example3a.c corrects this problem