Управление нитями Программирование с использованием POSIX thread library.

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
POSIX threads and C++ facilities Jakub Yaghob. Low-level threading and synchronization support Pthreads POSIX threads IEEE POSIX c (1995) C library.
TELE 402 Lecture 11: Advanced UDP… 1 by Dr Z. Huang Overview Last Lecture –Nonblocking I/O and ioctl operations –Source: Chapter 16 & 17 of Stevens’ book.
02/05/2008CSCI 315 Operating Systems Design1 Java Threads Notice: The slides for this lecture have been largely based on those accompanying an earlier.
Zombie and orphan processes. Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process A process is.
Job Control Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
OPERATING SYSTEMS 8 – VIRTUAL MEMORY PIETER HARTEL 1.
MultiCore Processing Workshop Multithreaded Programming using POSIX Threads(Pthreads) Syed Akbar Mehdi.
Threads Lab اللهم علمنا ما ينفعنا،،، وانفعنا بما علمتنا،،، وزدنا علماً
Chap. 23 Threads (1) Threads v.s. Fork (2) Basic Thread Functions #include int pthread_create ( pthread_t *tid, const pthread_attr_t *attr, void *(*func)(void.
Lecture 18 Threaded Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
28-Jun-15Advanced Programming Spring 2002 Unix processes and threads Henning Schulzrinne Dept. of Computer Science Columbia University.
Threads? Threads allow us to have multiple tasks active at the same time in one executable –think of a server handling multiple connections Each thread.
Семафоры-счетчики POSIX Программирование с использованием POSIX thread library.
Netprog Threads Programming1 Threads Programming Refs: Chapter 23.
Unix 教學. Unix-like System Linux FreeBSD Solaris Mac OS X …
Introduction to Pthreads. Pthreads Pthreads is a POSIX standard for describing a thread model, it specifies the API and the semantics of the calls. Model.
Processes Objectives –to become familiar with Unix processes Contents –processes & daemons –Nice levels –User limits –System resources –signals –batch.
PRINCIPLES OF OPERATING SYSTEMS Lecture 6: Processes CPSC 457, Spring 2015 May 21, 2015 M. Reza Zakerinasab Department of Computer Science, University.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Processes & Threads Emery Berger and Mark Corner University.
CS 590 Programming Environments with UNIX. Computer Lab Account Course Homepage
© D.Zinchin Introduction to Network Programming in UNIX & LINUX4-1 Thread Thread is separate part of process, providing it’s specific.
June-Hyun, Moon Computer Communications LAB., Kwangwoon University Chapter 26 - Threads.
Threads and Thread Control Thread Concepts Pthread Creation and Termination Pthread synchronization Threads and Signals.
Linux Programming –Threads CS Threads Review Threads in the same address space –share everything in the address space –lighter than process –no.
Multi-Thread Programming Vincent Liu MDE GPE-EA Sun Microsystems Inc.
Fall 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL1 Operating Systems Dr. Jerry Shiao, Silicon Valley University.
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Nezer J. Zaidenberg.  Advanced programming for the unix environment (chapters about processes)
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Unix 教學. Unix-like System Linux FreeBSD Solaris Mac OS X …
Synonyms: A _______ is a unit of software that is capable of executing concurrently with other similar units. _______ -- user-defined process in Ada _________.
Threads CSCE Thread Motivation Processes are expensive to create. Context switch between processes is expensive Communication between processes.
CSC Advanced Unix Programming, Fall, 2008 Monday, November 24 POSIX threads (pthreads)
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls.
Unix 教學 1. Unix-like System  Linux  FreeBSD  Solaris  Mac OS X  … 2.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Zombie and orphan processes. Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated so.
CSC552 Fall 2015 week 1 outline Parson, UNIX, and so forth
Об отладке программ МО ВВС ИВМ и МГ СО РАН Городничев Максим Александрович.
CS431-cotter1 Linux Programming, Processes, and Threads Man pages (fork, clone, execve, pthread_create) The Linux Programming Interface – Kerrisk, No Starch,
Concurrency I: Threads Nov 9, 2000 Topics Thread concept Posix threads (Pthreads) interface Linux Pthreads implementation Concurrent execution Sharing.
Threads. Progressing With Parallel Processing(PWPP?) eWeek (09/18/06) Vol. 23, No. 37, P. D5 Multithreading skills are becoming essential as parallel.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
Operating System Basics
Chapter 4: Threads.
Dynamic Analysis ddaa.
Netprog: Threads Programming
Thread Programming.
Linux 202 Training Module Program and Process.
Quicken capital one download error
Operating Systems Lecture 13.
Thread Programming.
Application Interface
When your program crashes
Operating System Concepts
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
class PrintOnetoTen { public static void main(String args[]) {
CSE 542: Operating Systems
CSE 542: Operating Systems
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2010.
Presentation transcript:

Управление нитями Программирование с использованием POSIX thread library

Функции управления pthread_self(3C) pthread_equal(3C) pthread_once(3C) sched_yield(3RT)

pthread_self(3C) #include pthread_t pthread_self(void); int pthread_equal(pthread_t t1, pthread_t t2);

pthread_once(3C) #include pthread_once_t once_control = PTHREAD_ONCE_INIT; int pthread_once( pthread_once_t *once_control, void (*init_routine)(void));

sched_yield(3RT) cc [ flags] file –lrt [ libraries ] #include int sched_yield(void); Нестандартная функция, эквивалент в Linux называется pthread_yield

Thread-specific data pthread_key_create(3C) pthread_key_delete(3C) pthread_setspecific(3C) pthread_getspecific(3C)

pthread_key_create #include int pthread_key_create( pthread_key_t *key, void (*destructor, void*)); Функция destructor вызывается при завершении нити.

pthread_get/setspecific #include int pthread_setspecific( pthread_key_t key, const void *value); int pthread_getspecific( pthread_key_t key);

Мониторинг исполнения программы -bash-3.00$ ps -efL UID PID PPID LWP NLWP C STIME TTY LTIME CMD daemon Sep 19 ? 0:00 /usr/lib/nfs/statd root Sep 19 ? 0:00 zsched root Sep 19 ? 0:00 /usr/lib/netsvc/yp/ypbind root Sep 19 ? 0:03 /sbin/init root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 1:14 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:14 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.startd root Sep 19 ? 0:00 /lib/svc/bin/svc.configd root Sep 19 ? 0:00 /lib/svc/bin/svc.configd root Sep 19 ? 0:00 /lib/svc/bin/svc.configd root Sep 19 ? 0:00 /lib/svc/bin/svc.configd root Sep 19 ? 0:01 /lib/svc/bin/svc.configd

Отладка - gdb Gdb: (gdb) info threads 3 process 35 thread 27 0x34e5 in sigpause () 2 process 35 thread 23 0x34e5 in sigpause () 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8) at threadtest.c:68 Команды –info threads –thread threadno –thread apply [threadno] [all] args

Отладка - dbx (dbx) threads a ?() running in main() ?() asleep on 0xef in_swtch() b ?() running in sigwait() consumer() asleep on 0x22bb0 in _lwp_sema_wait() b consumer() breakpoint in Queue_dequeue() b producer() running in _thread_start()

Отладка – SunStudio 11