1 / 13

POSIX Threads

POSIX Threads. Kevin Sawicki Rachel Strong. Overview. IEEE Standard Thread Basics Thread Safety Thread Characteristics POSIX comparison to Java. IEEE Standard 1003. Internationally known as ISO/IEC 9945 Developed jointly by IEEE and The Open Group

Download Presentation

POSIX Threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. POSIX Threads Kevin Sawicki Rachel Strong

  2. Overview • IEEE Standard • Thread Basics • Thread Safety • Thread Characteristics • POSIX comparison to Java

  3. IEEE Standard 1003 • Internationally known as ISO/IEC 9945 • Developed jointly by IEEE and The Open Group • POSIX replaced original name of IEEE-IX • Stands for Portable Operating System Interface • Name created by Richard Stallman • Incredibly long documents • Base Definitions over 500 pages • System Interfaces over 1750 pages

  4. POSIX Breadth • Defines a lot more than just threads: • Error Numbers • I/O Streams • Realtime • Sockets • Tracing • Outlines C Header files • Examples and code snippets are in C • Outlines concept of command interpreter or “shell”

  5. Thread Basics • IEEE Thread Definition: “A single flow of control within a process. Each thread has its own thread ID, scheduling priority and policy, errno value, thread-specific key/value bindings, and the required system resources to support a flow of control. Anything whose address may be determined by a thread, including but not limited to static variables, storage obtained via malloc( ), directly addressable storage obtained through implementation-defined functions, and automatic variables, are accessible to all threads in the same process.”

  6. Thread Contents • Each POSIX thread must maintain the following: • Thread ID (pthread_t) • Unique and reusable within the same process • Thread attributes (pthread_attr_t) • Scheduling information • Stack information • Cancellability State • Start routine • Arguments to start routine

  7. Thread Safety • Definition: • “A function that may be safely invoked concurrently by multiple threads.” • Standard outlines all functions that must be thread-safe • Defined as functions that lock on static storage or shared objects

  8. Mutually Exclusive locks • Defined data structure (pthread_mutex_t) • Configurable to multiple modes: • Normal  Relocking causes deadlock • Error Check  Error codes on incorrect calls • Recursive  Semaphore type behavior • Default All incorrect calls cause undefined behavior • Obtained two ways: • Via successful return from locking functions • Via return from wait functions • Released two ways: • Via success return from unlocking functions • Via blocking call to wait functions

  9. Conditional Variables • Defined data structure (pthread_cond_t) • Used to signal between threads on specific conditions • Wait and notification calls utilize conditionals • Must be used in conjunction with a mutex • Created through function call • Destroyed via function call

  10. pthread_create pthread_cond_wait pthread_signal pthread_broadcast pthread_exit pthread_join pthread_wait mutex and semaphore new and start no conditional waits, another object could notify when the condition was met notify notifyAll leave run method join wait synchronize POSIX vs. Java

  11. Real Time Java • RealtimeThread • Larger priority range • Control over scheduling algorithms • NoHeapRealtimeThread • Can preempt the garbage collector • More predictable and better control

  12. Conclusions • Java threads encourage a better program structure than POSIX threads. • Although with the addition of Real Time thread libraries to Java provides more control and it can approach C++ in some thread performance tests, for programs that need precise control and has hard deadlines Java Real Time threads are not the best choice.

  13. More Information • IEEE Standards available through: • http://ieeexplore.ieee.org • Freely accessible from RIT network • Select Standards and enter “1003” • The Open Group: • http://www.opengroup.org/onlinepubs/000095399/toc.htm • Man pages

More Related