Orbix TS Thread Library Reference

Size: px
Start display at page:

Download "Orbix TS Thread Library Reference"

Transcription

1 Orbix TS Thread Library Reference

2 Micro Focus The Lawn Old Bath Road Newbury, Berkshire RG14 1QN UK Copyright Micro Focus All rights reserved. MICRO FOCUS, the Micro Focus logo, and Micro Focus product names are trademarks or registered trademarks of Micro Focus Development Limited or its subsidiaries or affiliated companies in the United States, United Kingdom, and other countries. All other marks are the property of their respective owners ii

3 Contents Threading and Synchronization Toolkit Overview...1 Timeouts...1 Execution Modes...2 Wrapper Classes...2 Inlined Classes...2 Setting an Execution Mode...3 Errors and Exceptions...3 IT_Condition Class...7 IT_Condition::broadcast()...7 IT_Condition::IT_Condition() Constructor...7 IT_Condition::~IT_Condition() Destructor...8 IT_Condition::signal()...8 IT_Condition::wait()...8 IT_CurrentThread Class...9 IT_CurrentThread::cleanup()...9 IT_CurrentThread::id()...9 IT_CurrentThread::is_main_thread()...9 IT_CurrentThread::self()...9 IT_CurrentThread::sleep()...10 IT_CurrentThread::yield()...10 IT_DefaultTSErrorHandler Class...11 IT_DefaultTSErrorHandler::handle()...11 IT_DefaultTSErrorHandler::~IT_DefaultTSErrorHandler() Destructor...11 IT_Gateway Class...13 IT_Gateway::close()...13 IT_Gateway::IT_Gateway() Constructor...13 IT_Gateway::~IT_Gateway() Destructor...14 IT_Gateway::open()...14 IT_Gateway::wait()...14 IT_Locker Template Class...15 IT_Locker::cancel()...16 IT_Locker::is_locked()...16 IT_Locker::IT_Locker()...17 IT_Locker::~IT_Locker()...17 IT_Locker::lock()...18 IT_Locker::mutex()...18 IT_Locker::trylock()...18 IT_Mutex Class...19 IT_Mutex::IT_Mutex() Constructor...19 IT_Mutex::~IT_Mutex() Destructor...20 IT_Mutex::lock()...20 IT_Mutex::trylock()...20 Orbix TS Thread Library Reference iii

4 IT_Mutex::unlock()...20 IT_PODMutex Structure IT_PODMutex::lock()...21 IT_PODMutex::m_index Data Type...21 IT_PODMutex::trylock()...22 IT_PODMutex::unlock()...22 IT_RecursiveMutex Class IT_RecursiveMutex::IT_RecursiveMutex() Constructor...23 IT_RecursiveMutex::~IT_RecursiveMutex() Destructor...24 IT_RecursiveMutex::lock()...24 IT_RecursiveMutex::trylock()...24 IT_RecursiveMutex::unlock()...24 IT_RecursiveMutexLocker Class IT_RecursiveMutexLocker::cancel()...28 IT_RecursiveMutexLocker::IT_RecursiveMutexLocker() Constructors...29 IT_RecursiveMutexLocker::~IT_RecursiveMutexLocker() Destructor...29 IT_RecursiveMutexLocker::lock()...30 IT_RecursiveMutexLocker::lock_count()...30 IT_RecursiveMutexLocker::mutex()...30 IT_RecursiveMutexLocker::trylock()...30 IT_RecursiveMutexLocker::unlock()...30 IT_Semaphore Class IT_Semaphore::IT_Semaphore() Constructor...33 IT_Semaphore::~IT_Semaphore() Destructor...33 IT_Semaphore::post()...34 IT_Semaphore::trywait()...34 IT_Semaphore::wait()...34 IT_TerminationHandler Class IT_TerminationHandler()...35 ~IT_TerminationHandler()...36 IT_Thread Class IT_Thread::id()...37 IT_Thread::is_null()...38 IT_Thread::IT_Thread() Constructors...38 IT_Thread::~IT_Thread() Destructor...38 IT_Thread::join()...38 IT_Thread::operator=()...39 IT_Thread::operator==()...39 IT_Thread::operator!=()...39 IT_Thread::thread_failed Constant...39 IT_ThreadBody Class IT_ThreadBody::~IT_ThreadBody() Destructor...41 IT_ThreadBody::run()...41 IT_ThreadFactory Class IT_ThreadFactory::DetachState Enumeration...43 IT_ThreadFactory::IT_ThreadFactory() Constructor...43 iv Orbix TS Thread Library Reference

5 IT_ThreadFactory::~IT_ThreadFactory() Destructor IT_ThreadFactory::smf_start() IT_ThreadFactory::start() IT_TimedCountByNSemaphore Class...45 IT_TimedCountByNSemaphore::infinite_size Constant IT_TimedCountByNSemaphore::infinite_timeout Constant IT_TimedCountByNSemaphore::IT_TimedCountByNSemaphore() Constructor. 46 IT_TimedCountByNSemaphore::~IT_TimedCountByNSemaphore() Destructor 46 IT_TimedCountByNSemaphore::post() IT_TimedCountByNSemaphore::trywait() IT_TimedCountByNSemaphore::wait() IT_TimedOneshot Class...49 IT_TimedOneshot::infinite_timeout Constant IT_TimedOneshot::IT_TimedOneshot() Constructor IT_TimedOneshot::~IT_TimedOneshot() Destructor IT_TimedOneshot::reset() IT_TimedOneshot::signal() IT_TimedOneshot::trywait() IT_TimedOneshot::wait() IT_TimedSemaphore Class...53 IT_TimedSemaphore::infinite_timeout Constant IT_TimedSemaphore::IT_TimedSemaphore() Constructor IT_TimedSemaphore::~IT_TimedSemaphore() Destructor IT_TimedSemaphore::post() IT_TimedSemaphore::trywait() IT_TimedSemaphore::wait() IT_TSBadAlloc Error Class...57 IT_TSError Error Class...59 IT_TSError::IT_TSError() Constructors IT_TSError::~IT_TSError() Destructor IT_TSError::OS_error_number() IT_TSError::raise() IT_TSError::TS_error_code() IT_TSError::what() IT_TSErrorHandler Class...61 IT_TSErrorHandler::handle() IT_TSErrorHandler::~IT_TSErrorHandler() Destructor IT_TSLogic Error Class...63 IT_TSRuntime Error Class...65 IT_TSVoidStar Class...67 IT_TSVoidStar::IT_TSVoidStar() Constructor IT_TSVoidStar::~IT_TSVoidStar() Destructor IT_TSVoidStar::get() IT_TSVoidStar::set() Orbix TS Thread Library Reference v

6 vi Orbix TS Thread Library Reference

7 Threading and Synchronization Toolkit Overview The Threading and Synchronization (TS) toolkit provides an object-oriented and platform-neutral abstraction that hides the diverse, lower-level, thread packages. Table 1 shows the threading and synchronization (TS) classes organized into some useful groups. Table 1: TS Thread Classes Thread Management Thread Errors and Exceptions Mutex Locks Thread Synchronization IT_CurrentThread IT_Thread IT_ThreadBody IT_ThreadFactory IT_TerminationHandler IT_TSVoidStar IT_TSBadAlloc IT_DefaultTSErrorHandler IT_TSError IT_TSErrorHandler IT_TSLogic IT_TSRuntime IT_Locker IT_Mutex IT_PODMutex IT_RecursiveMutex IT_RecursiveMutexLocker IT_Condition IT_Gateway IT_Semaphore IT_TimedCountByNSemaphore IT_TimedOneshot IT_TimedSemaphore The rest of this overview covers these topics: Timeouts Execution Modes Errors and Exceptions Timeouts Timeouts are expressed in milliseconds. They represent the time period from the invocation of the timed method until the expiration of the timer. This time-out period is approximate because it is affected by the number and kind of interrupts received and by the changes external sources may make to the system s time. Orbix TS Thread Library Reference 1

8 Execution Modes The TS classes are designed to be efficient and to help you write code that is correct and portable across various platforms. You can build TS applications in either of the following modes: Unchecked Checked This is the normal production mode. Inexpensive checks, such as checking values returned by the API, are performed, but a minimum of memory, locking, and system calls are used to implement TS features. In this mode, extra-checking is performed to detect erroneous or non-portable situations. On platforms that support exceptions, exceptions are raised to report such errors. This mode may be less time or space efficient than the unchecked mode. The effect of a program that runs correctly (the program does not create any TS error object) in the checked mode is identical to that of the unchecked mode. TS provides two kinds of classes in different sets of header files. These include wrapper and inline classes. Wrapper Classes Wrapper classes are the recommended classes to use because you can switch between checked and unchecked modes by simply re-linking without recompiling your application. These clean, platform-neutral wrapper classes simply delegate to the appropriate inlined classes for whichever mode you are using. The wrapper classes are in header files ending in.h. Inlined Classes To minimize the delegation overhead of wrapper classes, the TS toolkit also provides C++ classes with only inlined member methods and pre-preprocessor directives. These inline classes accommodate the differences between the underlying thread packages. Delegation overhead for a normal method call is generally negligible, but you can save on this overhead by using these inlined classes directly. However by using these header files, you will need to recompile your application whenever you want to switch between checked and unchecked modes, and each time even minor improvements are made to the TS implementation. The inline classes are in header files ending in _i.h. 2 Orbix TS Thread Library Reference

9 Setting an Execution Mode Table 2 shows the default settings for each platform. Table 2: Default Thread Settings Platform Thread Primitives Default Mode HPUX 11 Solaris 2.6 Posix unchecked HPUX DCE unchecked Other Solaris UI unchecked Win32 Win32 unchecked Win 64 Win64 unchecked To set a different mode, you reset the library by inserting the preferred lib subdirectory at the beginning of your LD_LIBRARY_PATH or SHLIB_PATH. For example, to reset to the checked mode, do the following for your respective platform: Solaris HPUX HPUX Win32 Win64 Put the following at the beginning of your LD_LIBRARY_PATH: /vob/common/ts/lib/posix/checked Put the following at the beginning of your SHLIB_PATH: /vob/common/ts/lib/dce/checked Put the following at the beginning of your SHLIB_PATH: /vob/common/ts/lib/posix/checked Put the following at the beginning of your PATH: /common/ts/lib/win32/checked Put the following at the beginning of your PATH: /common/ts/lib/win64/checked Errors and Exceptions Table 3 summarizes the TS error classes: Table 3: Error and Exception Classes Control IT_DefaultTSErrorHandler IT_TSError IT_TSErrorHandler IT_TSBadAlloc IT_TSLogic IT_TSRuntime Exceptions The TS API allows you to use either error parameters or exceptions. The last parameter of almost every TS method is a reference to an error handler object of the class IT_TSErrorHandler. When a TS method detects an error, it creates an IT_TSError object and passes it to IT_TSErrorHandler::handle(). Orbix TS Thread Library Reference 3

10 TS errors form the hierarchy shown in Figure 1. An IT_TSRuntime error generally signals an error detected by the operating system or the underlying thread package. An IT_TSLogic error reports a logic error in your program, for example, when a thread tries to release a lock it does not own. Logic errors are either detected by the underlying thread package, or by extra checking code in checked mode. An IT_TSBadAlloc error signals that the new operator failed. IT_TSError IT_TSRuntime IT_TSLogic IT_TSBadAlloc Figure 1: The TS Error Class Hierarchy The TS API provides a default, static, and stateless error handler named IT_DefaultTSErrorHandler. If you use exceptions, this error handler throws IT_TSError objects. In environments that do not use exceptions this handler aborts the process. For most applications, the default error handler object provides the desired bavior. In this situation, instead of passing an IT_DefaultTSErrorHandler object each time you call a TS method, you can define in your build command the environment variable IT_TS_DEFAULTED. This will instruct the TS API to use the default error handler object for the error handler parameter. For example: #ifndef IT_TS_DEFAULT_ERROR_HANDLER #ifdef IT_TS_DEFAULTED #define IT_TS_DEFAULT_ERROR_HANDLER = IT_DefaultTSErrorHandler #else #define IT_TS_DEFAULT_ERROR_HANDLER #endif #endif C++ destructors do not have parameters, and as result, cannot be given an error handler object parameter. In the checked mode, the TS API reports errors in destructors to the default error handler object. In the unchecked mode, the TS API does not report errors that occur in destructors. Because default parameters are not part of the function-type in C++, the TS library can be built with or without defining IT_TS_DEFAULTED. Also, the same library can be used by modules that use the defaulted parameter and by modules built without defining IT_TS_DEFAULTED. 4 Orbix TS Thread Library Reference

11 If you intend to use your own error handler objects in your application, it is strongly recommended that you do not define IT_TS_DEFAULTED to avoid using the default error handler object by mistake. If you want to consistently use the same error handler object, you can define IT_TS_DEFAULT_ERROR_HANDLER in your command or in a non-exported file. For example: #define IT_TS_DEFAULT_ERROR_HANDLER = myerrorhandler; Orbix TS Thread Library Reference 5

12 6 Orbix TS Thread Library Reference

13 IT_Condition Class The IT_Condition class provides a signalling mechanism that events use to synchronize when sharing a mutex. In one atomic operation, a condition wait both releases the mutex and waits until another thread signals or broadcasts a change of state for the condition. class IT_Condition public: IT_Condition( ~IT_Condition( void wait( IT_Mutex& app_mutex, void wait( IT_MutexLocker& locker, void signal( void broadcast( ; IT_Condition::broadcast() void broadcast( Wakes up all waiting threads. One thread acquires the mutex and resumes with the associated mutex lock. The rest of the threads continue waiting. See Also IT_Mutex IT_Condition::IT_Condition() Constructor IT_Condition( The constructor for an IT_Condition object. Orbix TS Thread Library Reference 7

14 IT_Condition::~IT_Condition() Destructor ~IT_Condition( The destructor for an IT_Condition object. IT_Condition::signal() void signal( Wakes up a single waiting thread. The thread resumes with the associated mutex locked. IT_Condition::wait() void wait( IT_Mutex& app_mutex, void wait( IT_MutexLocker& locker, Atomically releases the mutex, and waits until another thread calls signal() or broadcast(). app_mutex locker Use the mutex app_mutex. Use the mutex in locker. The mutex must always be locked when wait() is called. When a condition wakes up from a wait, it resumes with the mutex locked. 8 Orbix TS Thread Library Reference

15 IT_CurrentThread Class The IT_CurrentThread class gives access to the current thread. It has only static member methods. class IT_TS_API IT_CurrentThread public: static IT_Thread self( static int is_main_thread( static void cleanup( static void yield( static void sleep( unsigned long milliseconds ; static long id( IT_CurrentThread::cleanup() static void cleanup( Cleans up thread-specific data. A thread typically calls cleanup() before exiting. Threads created with an IT_ThreadFactory do this automatically. IT_CurrentThread::id() static long id( Returns a unique identifier for the current thread. IT_CurrentThread::is_main_thread() static int is_main_thread( Returns 1 if the caller is the main thread, but returns 0 if it is not. IT_CurrentThread::self() static IT_Thread self( Orbix TS Thread Library Reference 9

16 Returns an IT_Thread object for the thread that calls this method. IT_CurrentThread::sleep() static void sleep( unsigned long milliseconds Suspends the current thread for the approximate number of milliseconds input. milliseconds The length of time in milliseconds to suspend the thread. IT_CurrentThread::yield() static void yield( Yields the CPU to another thread of equal priority, if one is available. 10 Orbix TS Thread Library Reference

17 IT_DefaultTSErrorHandler Class The IT_DefaultTSErrorHandler class is the default TS error handler. If you use exceptions, this error handler throws IT_TSError objects. In environments that do not use exceptions this handler aborts the process. class IT_DefaultTSErrorHandler : public IT_TSErrorHandler public: virtual ~IT_DefaultTSErrorHandler() virtual void handle( const IT_TSError& this_error ; See page 3 for more on error handling. IT_DefaultTSErrorHandler::handle() void handle( const IT_TSError& this_error Do appropriate processing for the given error. this_error A reference to an error object. IT_DefaultTSErrorHandler::~IT_DefaultTSErro rhandler() Destructor ~IT_DefaultTSErrorHandler() The destructor for the error handler object. Orbix TS Thread Library Reference 11

18 12 Orbix TS Thread Library Reference

19 IT_Gateway Class The IT_Gateway class provides a gate where a set of threads can only do work if the gate is open. class IT_Gateway public: IT_Gateway( ~IT_Gateway( void open( void close( void wait( private:... IT_Gateway::close() void close( Close the gateway so no threads can do any work. IT_Gateway::IT_Gateway() Constructor IT_Gateway( The gateway constructor. Orbix TS Thread Library Reference 13

20 IT_Gateway::~IT_Gateway() Destructor ~IT_Gateway( The destructor. IT_Gateway::open() void open( Open the gateway to allow threads to work. IT_Gateway::wait() void wait( Wait for a thread to finish. 14 Orbix TS Thread Library Reference

21 IT_Locker Template Class IT_Locker is a helper class for locking and unlocking non-recursive mutexes, including IT_Mutex and IT_PODMutex objects. Typically a locker locks a mutex in its constructor and releases it in its destructor. This is particularly useful for writing clean code that baves properly when an exception is raised. An IT_Locker object must be created on the stack of a particular thread, and must never be shared by more than one thread. The IT_Locker method definitions are inlined directly in the class declaration, because these methods call each other. If a definition calls a method that is not previously declared inlined, this method is generated out of line, regardless of its definition (which can be provided later in the translation unit with the inline keyword). template<class T> class IT_Locker public: IT_Locker( T& mutex, ) : m_mutex(mutex), m_locked(0), m_error_handler() lock( IT_Locker( T& mutex, int wait, ) : m_mutex(mutex), m_locked(0), m_error_handler() if (wait) lock( else trylock( ~IT_Locker() cancel( void cancel() if (m_locked) m_mutex.unlock(m_error_handler Orbix TS Thread Library Reference 15

22 m_locked = 0; int is_locked() return m_locked; void lock() m_mutex.lock(m_error_handler m_locked = 1; int trylock() return (m_locked = m_mutex.trylock(m_error_handler) T& mutex() return m_mutex; private:... IT_Locker::cancel() Exceptions void cancel() if (m_locked) m_mutex.unlock(m_error_handler m_locked = 0; Releases the mutex only if it is locked by this locker. You can call cancel() safely even when the mutex is not locked. Errors that can be reported include: IT_TSRuntime IT_TSLogic IT_Locker::is_locked() int is_locked() return m_locked; returns 1 if this mutex locker has the lock and returns 0 if it does not. 16 Orbix TS Thread Library Reference

23 IT_Locker::IT_Locker() IT_Locker( T& mutex, ) : m_mutex(mutex), m_locked(0), m_error_handler() lock( A constructor for a locker object that locks the given mutex. IT_Locker( T& mutex, int wait, ) : m_mutex(mutex), m_locked(0), m_error_handler() if (wait) lock( else trylock( A constructor for a locker object. mutex wait The mutex to which the locker applies. If wait has a value of 1, this constructor waits to acquire the lock. If wait has a value of 0, the constructor only tries to lock the mutex. See Also IT_Locker::trylock() IT_Locker::~IT_Locker() Exceptions ~IT_Locker() cancel( The destructor releases the mutex if it is locked by this locker. Errors that can be reported include: IT_TSLogic IT_TSRuntime Orbix TS Thread Library Reference 17

24 IT_Locker::lock() Exceptions void lock() m_mutex.lock(m_error_handler m_locked = 1; Locks the mutex associated with the locker. Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_Locker::mutex() T& mutex() return m_mutex; Returns direct access to the locker s mutex. IT_Locker::trylock() Exceptions int trylock() return (m_locked = m_mutex.trylock(m_error_handler) Tries to lock the mutex. Returns 1 if the mutex is successfully locked or 0 if it is not locked. Errors that can be reported include: IT_TSLogic IT_TSRuntime 18 Orbix TS Thread Library Reference

25 IT_Mutex Class An IT_Mutex object is a synchronization primitive for mutual exclusion locks. When a thread has successfully locked, it is said to own the IT_Mutex. IT_Mutex objects have scope only within a single process (they are not shared by several processes) and they are not recursive. When a thread that owns an IT_Mutex attempts to lock it again, a deadlock occurs. You use an IT_Mutex in conjunction with an IT_Locker object to lock and unlock your mutexes. class IT_Mutex public: IT_Mutex( ~IT_Mutex( void lock( void unlock( int trylock( See Also private: // ; IT_Locker IT_RecursiveMutex IT_Mutex::IT_Mutex() Constructor IT_Mutex(I Constructs an IT_Mutex object. It is initially unlocked. Exceptions The IT_TSRuntime error can be reported. Orbix TS Thread Library Reference 19

26 IT_Mutex::~IT_Mutex() Destructor IT_Mutex( The destructor for the mutex. IT_Mutex::lock() void lock( Blocks until the IT_Mutex can be acquired. Exceptions Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_Mutex::trylock() int trylock( Tries to acquire the lock. If successful, the method returns a 1 immediately, otherwise it returns a 0 and does not block. Exceptions Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_Mutex::unlock() void unlock( Releases this IT_Mutex. Only the owner thread of an IT_Mutex is allowed to release an IT_Mutex. Exceptions Errors that can be reported include: IT_TSLogic IT_TSRuntime 20 Orbix TS Thread Library Reference

27 IT_PODMutex Structure See Also An IT_PODMutex is a mutex for a plain old data (POD) structure. Just as with a standard C++ PODS, an IT_PODMutex can be fully initialized at compile time without the overhead of an explicit constructor call. This is particularly useful for static objects. Likewise, the object can be destroyed without an explicit destructor call (in a manner similar to the C language). You can use the built-in definition IT_POD_MUTEX_INIT to easily initialize an IT_PODMutex to zero. For example: static IT_PODMutex my_global_mutex = IT_POD_MUTEX_INIT; You use an IT_PODMutex in conjunction with an IT_Locker object to lock and unlock your mutexes. The structure members for an IT_PODMutex include the following: struct IT_TS_API IT_PODMutex void lock( int trylock( void unlock( // DO NOT USE and DO NOT MAKE PRIVATE unsigned char m_index; ; IT_Locker IT_Mutex IT_PODMutex::lock() void lock( Blocks until the mutex can be acquired. Exceptions Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_PODMutex::m_index Data Type Note: unsigned char m_index; For internal use only. Orbix TS Thread Library Reference 21

28 IT_PODMutex::trylock() int trylock( Tries to acquire the mutex lock. If trylock() succeeds, it returns a 1 immediately. Otherwise it returns 0. Exceptions Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_PODMutex::unlock() void unlock( Releases the mutex lock. Only the owner of a mutex is allowed to release it. Exceptions Errors that can be reported include: IT_TSLogic IT_TSRuntime 22 Orbix TS Thread Library Reference

29 IT_RecursiveMutex Class An IT_RecursiveMutex object is a synchronization primitive for mutual exclusion. In general do not used it directly. Note: It is strongly recommended that you use the IT_RecursiveMutexLocker to lock and unlock your recursive mutexes. In most respects an IT_RecursiveMutex object is similar to an IT_Mutex object. However, it can be locked recursively, which means that a thread that already owns a recursive mutex object can lock it again in a deeper scope without creating a deadlock condition. When a thread has successfully locked a recursive mutex, it is said to own it. Recursive mutex objects have process-scope which means that they are not shared by several processes. To release an IT_RecursiveMutex, its owner thread must call unlock() the same number of times that it called lock(). class IT_RecursiveMutex public: IT_RecursiveMutex( ~IT_RecursiveMutex( void lock( void unlock( See Also int trylock( private:... IT_Mutex IT_RecursiveMutexLocker IT_RecursiveMutex::IT_RecursiveMutex() Constructor IT_RecursiveMutex( Constructs an IT_RecursiveMutex object. It is initially unlocked. Orbix TS Thread Library Reference 23

30 Exceptions The IT_TSRuntime error can be reported. IT_RecursiveMutex::~IT_RecursiveMutex() Destructor ~IT_RecursiveMutex( Destructor for an IT_RecursiveMutex object. IT_RecursiveMutex::lock() void lock( Blocks until the recursive mutex can be acquired. Exceptions The IT_TSRuntime error can be reported. IT_RecursiveMutex::trylock() int trylock( Tries to acquire the recursive mutex. If it succeeds, returns 1 immediately; otherwise returns 0. Exceptions The IT_TSRuntime error can be reported. IT_RecursiveMutex::unlock() void unlock( Releases this recursive mutex (one count). Only the owner of a mutex is allowed to release it. 24 Orbix TS Thread Library Reference

31 Exceptions Errors that can be reported include: IT_TSRuntime IT_TSLogic Orbix TS Thread Library Reference 25

32 26 Orbix TS Thread Library Reference

33 IT_RecursiveMutexLocker Class The IT_RecursiveMutexLocker is a locker for recursive mutexes. The IT_RecursiveMutexLocker methods are defined as inline in the class declaration, because these methods call each other. class IT_RecursiveMutexLocker public: IT_RecursiveMutexLocker( IT_RecursiveMutex& m, ) : m_recursive_mutex(m), m_lock_count(0), m_error_handler() lock( IT_RecursiveMutexLocker( IT_RecursiveMutex& m, int wait, ) : m_recursive_mutex(m), m_lock_count(0), m_error_handler() if (wait) lock( else trylock( ~IT_RecursiveMutexLocker() cancel( void cancel() while (m_lock_count > 0) m_recursive_mutex.unlock(m_error_handler m_lock_count--; void lock() m_recursive_mutex.lock(m_error_handler m_lock_count++; Orbix TS Thread Library Reference 27

34 unsigned int lock_count() return m_lock_count; int trylock() if (m_recursive_mutex.trylock(m_error_handler) == 1) m_lock_count++; return 1; else return 0; void unlock() m_recursive_mutex.unlock(m_error_handler m_lock_count--; IT_RecursiveMutex& mutex() return m_recursive_mutex; Private:... IT_RecursiveMutexLocker::cancel() void cancel() while (m_lock_count > 0) m_recursive_mutex.unlock(m_error_handler m_lock_count--; Releases all locks held by this recursive mutex locker. The cancel() method can be called safely even when the recursive mutex is not locked. 28 Orbix TS Thread Library Reference

35 IT_RecursiveMutexLocker::IT_RecursiveMutex Locker() Constructors IT_RecursiveMutexLocker( IT_RecursiveMutex& m, ) : m_recursive_mutex(m), m_lock_count(0), m_error_handler() lock( Constructs a recursive mutex locker object. This constructor locks the given recursive mutex. IT_RecursiveMutexLocker( IT_RecursiveMutex& m, int wait, ) : m_recursive_mutex(m), m_lock_count(0), m_error_handler() if (wait) lock( else trylock( Constructs a recursive mutex locker object. m wait The mutex to which the locker applies. If wait has a value of 1, this constructor waits to acquire the lock. If wait has a value of 0, it only tries to lock the recursive mutex. IT_RecursiveMutexLocker::~IT_RecursiveMut exlocker() Destructor ~IT_RecursiveMutexLocker() cancel( The destructor releases all locks held by this recursive mutex locker. Orbix TS Thread Library Reference 29

36 IT_RecursiveMutexLocker::lock() void lock() m_recursive_mutex.lock(m_error_handler m_lock_count++; Acquires the lock. IT_RecursiveMutexLocker::lock_count() unsigned int lock_count() return m_lock_count; Returns the number of locks held by this recursive mutex locker. IT_RecursiveMutexLocker::mutex() IT_RecursiveMutex& mutex() return m_recursive_mutex; Returns direct access to the locker s recursive mutex. IT_RecursiveMutexLocker::trylock() int trylock() if (m_recursive_mutex.trylock(m_error_handler) == 1) m_lock_count++; return 1; else return 0; Tries to acquire one lock for the recursive mutex. Returns 1 if the mutex lock is successfully acquired or 0 if it is not. IT_RecursiveMutexLocker::unlock() void unlock() 30 Orbix TS Thread Library Reference

37 m_recursive_mutex.unlock(m_error_handler m_lock_count--; Releases one lock held by this recursive mutex. Orbix TS Thread Library Reference 31

38 32 Orbix TS Thread Library Reference

39 IT_Semaphore Class A semaphore is a non-negative counter, typically used to coordinate access to some resources. class IT_Semaphore public: IT_Semaphore( size_t initialcount, ~IT_Semaphore( void post( void wait( int trywait( private: // ; IT_Semaphore::IT_Semaphore() Constructor IT_Semaphore( size_t initialcount, A semaphore constructor that initializes the semaphore s counter with the value initialcount. initialcount A positive integer value. Exceptions The IT_TSRuntime error can be reported. IT_Semaphore::~IT_Semaphore() Destructor ~IT_Semaphore( Destroys the semaphore. Orbix TS Thread Library Reference 33

40 IT_Semaphore::post() void post( Posts a resource thread with the semaphore. This method increments the semaphore s counter and wakes up a thread that might be blocked on wait(). Exceptions The IT_TSRuntime error can be reported. IT_Semaphore::trywait() int trywait( Tries to get a resource thread. The method returns 1 if it succeeds, and 0 if it fails. Exceptions An error that can be reported is IT_TSRuntime. IT_Semaphore::wait() void wait( Waits for one resource. The wait() method blocks if the semaphore s counter value is 0 and decrements the counter if the counter s value is greater than 0. Exceptions See Also Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_TimedSemaphore IT_TimedCountByNSemaphore 34 Orbix TS Thread Library Reference

41 IT_TerminationHandler Class The IT_TerminationHandler class enables server applications to handle delivery of CTRL_C and similar events in a portable manner. On UNIX, the termination handler handles the following signals: SIGINT SIGTERM SIGQUIT On Windows, the termination handler is a wrapper around SetConsoleCtrlHandler, which handles delivery of the following control events: CTRL_C_EVENT CTRL_BREAK_EVENT CTRL_SHUTDOWN_EVENT CTRL_LOGOFF_EVENT CTRL_CLOSE_EVENT You can create only one termination handler object in a program. #include <it_ts/ts_error.h> typedef void (*IT_TerminationHandlerFunctionPtr)(long class IT_IFC_API IT_TerminationHandler public: IT_TerminationHandler( IT_TerminationHandlerFunctionPtr f, IT_ExceptionHandler& = IT_EXCEPTION_HANDLER ; ~IT_TerminationHandler( IT_TerminationHandler() IT_TerminationHandler( IT_TerminationHandlerFunctionPtr f, IT_ExceptionHandler& = IT_EXCEPTION_HANDLER Creates a termination handler object on the stack. On POSIX platforms, it is critical to create this object in the main thread before creation of any other thread, and especially before ORB initialization. f The callback function registered by the application. The callback function takes a single long argument: On UNIX, the signal number on Unix/POSIX On Windows, the type of event caught Orbix TS Thread Library Reference 35

42 ~IT_TerminationHandler() ~IT_TerminationHandler( Deregisters the callback, in order to avoid calling it during static destruction. 36 Orbix TS Thread Library Reference

43 IT_Thread Class An IT_Thread object represents a thread of control. An IT_Thread object can be associated with a running thread, associated with a thread that has already terminated, or it can be null, which means it is not associated with any thread. The important class members are as follows: class IT_Thread public: IT_Thread( ~IT_Thread( IT_Thread( const IT_Thread& other IT_Thread& operator=( const IT_Thread& other int operator==( const IT_Thread& x ) const; int operator!=( const IT_Thread& x ) const return! operator==(x int is_null() const; static void* const thread_failed; void* join( ) const;... ; long id() const; IT_Thread::id() long id() const; Returns a unique thread identifier. This method is useful for debugging. Orbix TS Thread Library Reference 37

44 IT_Thread::is_null() int is_null() const; Tests if this is a null IT_Thread object. IT_Thread::IT_Thread() Constructors IT_Thread( IT_Thread_i* t=0 Constructs a null IT_Thread object. IT_Thread ( const IT_Thread& other Copies the IT_Thread object. This constructor does not start a new thread. other The original thread to copy. IT_Thread::~IT_Thread() Destructor ~IT_Thread( Destructor for an IT_Thread object. IT_Thread::join() void* join( ) const; Waits until the thread has terminated and returns its exit status. At most one thread can successfully join a given thread, and only Attached threads can be joined. Note that even in the checked mode, join() does not always detect that you tried to join a Detached thread, or that you joined the same thread several times. Exceptions See Also Errors that can be reported include: IT_TSLogic IT_TSRuntime IT_CurrentThread IT_ThreadBody 38 Orbix TS Thread Library Reference

45 IT_Thread::operator=() IT_Thread& operator=( const IT_Thread& other Assignment operator that copies the IT_Thread object. This does not start a new thread. other The original thread that is copied. IT_Thread::operator==() int operator==( const IT_Thread& x ) const; Operator that checks if two IT_Thread objects refer to the same thread. Returns 1 if the two objects refer to the same thread or it returns 0 if they do not refer to the same thread. x The thread to compare to this thread. IT_Thread::operator!=() int operator!=( const IT_Thread& x ) const Operator that checks if two IT_Thread objects refer to different threads. Returns 1 if the two objects refer to different threads or it returns 0 if they refer to the same thread. x The thread to compare to this thread. IT_Thread::thread_failed Constant static void* const thread_failed; The constant thread_failed is the return status of a thread to report a failure. It is neither NULL nor does it denote a valid address. Orbix TS Thread Library Reference 39

46 40 Orbix TS Thread Library Reference

47 IT_ThreadBody Class IT_ThreadBody is the base class for thread execution methods. To start a thread, derive a class from IT_ThreadBody, add any data members needed by the thread, and provide a run() method which does the thread's work. Then use an IT_ThreadFactory object to start a thread that will execute the run() method of your IT_ThreadBody object. If a derived IT_ThreadBody contains data, then it must not be destroyed while threads are using it. One way to manage this is to allocate the IT_ThreadBody with the new() operator and have the IT_ThreadBody delete itself at the end of run(). Also, if multiple threads run the same IT_ThreadBody, it is up to you to provide synchronization on shared data. class IT_ThreadBody public: virtual ~IT_ThreadBody() ; virtual void* run() =0; IT_ThreadBody::~IT_ThreadBody() Destructor virtual ~IT_ThreadBody( The destructor for the IT_ThreadBody object. IT_ThreadBody::run() Exceptions virtual void* run() =0; Does the work and returns a status, which is typically NULL or the address of a static object. On platforms that support exceptions, if run() throws an exception while used by an attached thread, this thread s exit status will be IT_Thread::thread_failed. Orbix TS Thread Library Reference 41

48 42 Orbix TS Thread Library Reference

49 IT_ThreadFactory Class An IT_ThreadFactory object starts threads that share some common properties. You can derive your own class from IT_ThreadFactory to control other aspect of thread creation, such as the exact method used to create or start the thread, or the priority of threads when they are created. class IT_ThreadFactory public: enum DetachState Detached, Attached ; IT_ThreadFactory( DetachState detachstate, size_t stacksize =0 virtual ~IT_ThreadFactory( virtual IT_Thread start( IT_ThreadBody& body, static IT_Thread smf_start( IT_ThreadBody& body, DetachState detach_state, size_t stack_size, protected:... IT_ThreadFactory::DetachState Enumeration enum DetachState Detached, Attached ; A thread can be started in a detached or attached state. If a thread is detached, you cannot join it (retrieve its exit status). If a thread is attached you must join it to tell the operating system to forget about it. IT_ThreadFactory::IT_ThreadFactory() Constructor IT_ThreadFactory( DetachState detachstate, size_t stacksize = 0 Constructor for an IT_ThreadFactory object. Orbix TS Thread Library Reference 43

50 detachstate stacksize Specify whether the manufactured threads are Detached or Attached. Optionally specify the stack size of your threads (expressed in bytes). A value of 0 (the default) means that the operating system will use a default. See Also IT_Thread::join() IT_ThreadFactory::~IT_ThreadFactory() Destructor virtual ~IT_ThreadFactory( The destructor for a thread factory object. IT_ThreadFactory::smf_start() See Also static IT_Thread smf_start( IT_ThreadBody& body, DetachState detach_state, size_t stack_size, A static member method (smf) that starts a thread without creating a thread factory explicitly. This method is useful for simple examples and prototyping but is not as flexible for robust applications. IT_ThreadFactory::start() IT_ThreadFactory::start() virtual IT_Thread start( IT_ThreadBody& body, Starts a thread. This method creates an operating system thread that runs the given body. The method returns an IT_Thread object that represents this thread. body The thread body to run. Exceptions See Also An error that can be reported includes IT_TSRuntime. IT_Thread IT_ThreadBody 44 Orbix TS Thread Library Reference

51 IT_TimedCountByNSemaphore Class This semaphore is a non-negative counter typically used to coordinate access to a set of resources. Several resources can be posted or waited for atomically. For example, if there are five resources available, a thread that asks for seven resources would wait but another thread that later asks for three resources would succeed, taking three resources. class IT_TimedCountByNSemaphore public: enum infinite_timeout = -1 ; enum infinite_size = 0 ; IT_TimedCountByNSemaphore( size_t initial_count, size_t max_size, ~IT_TimedCountByNSemaphore( void post( size_t n, void wait( size_t n, int wait( size_t n, long timeout, int trywait( size_t n, private:... ; IT_TimedCountByNSemaphore::infinite_size Constant See Also enum infinite_size = 0 ; A constant used to indicate an infinite sized semaphore. IT_TimedCountByNSemaphore::wait() Orbix TS Thread Library Reference 45

52 IT_TimedCountByNSemaphore::infinite_timeo ut Constant See Also enum infinite_timeout = -1 ; A constant used to indicate there is no time-out period for the semaphore. IT_TimedCountByNSemaphore::wait() IT_TimedCountByNSemaphore::IT_TimedCoun tbynsemaphore() Constructor Exceptions IT_TimedCountByNSemaphore( size_t initial_count, size_t max_size, Initializes the semaphore with initial_count and sets its maximum size to max_size. An error that can be reported is IT_TSRuntime. IT_TimedCountByNSemaphore::~IT_TimedCo untbynsemaphore() Destructor ~IT_TimedCountByNSemaphore( The destructor for the semaphore. IT_TimedCountByNSemaphore::post() void post( size_t n, Posts the number of resources managed. n The number of resources. If the value of n plus the previous number of resources is greater than max_size, then the number of resources remains unchanged and an IT_TSLogic error is reported. Calling the method using a value of 0 does nothing. Exceptions Errors that can be reported include: IT_TSRuntime IT_TSLogic 46 Orbix TS Thread Library Reference

53 IT_TimedCountByNSemaphore::trywait() Exceptions See Also int trywait( size_t n, Equivalent to a wait(n, 0, ). An error that can be reported is IT_TSRuntime. IT_TimedCountByNSemaphore::wait() IT_TimedCountByNSemaphore::wait() void wait( size_t n, Attempts to take a set of resources atomically. int wait( size_t n, long timeout, Attempts to take a set of resources (n) atomically. Returns 1 upon success or 0 when the operation times out. Calling wait(0, timeout, ) returns 1 immediately. n The number of resources attempted. A value of 0 causes the methods to return immediately. timeout The number of milliseconds before the call gives up. You can use the constant infinite_timeout. Exceptions See Also IT_Semaphore and IT_TimedSemaphore can be more efficient than IT_TimedCountByNSemaphore when resources are posted and waited for one by one. An error that can be reported is IT_TSRuntime. IT_Semaphore IT_TimedSemaphore Orbix TS Thread Library Reference 47

54 48 Orbix TS Thread Library Reference

55 IT_TimedOneshot Class An IT_TimedOneshot class is a synchronization policy typically used to establish a rendezvous between two threads. It can have three states: RESET SIGNALED WAIT The key class members are as follows: class IT_TimedOneshot public: enum infinite_timeout = -1 ; IT_TimedOneshot( ~IT_TimedOneshot( void signal( void reset( void wait( int wait( long timeout, int trywait(... ; IT_TimedOneshot::infinite_timeout Constant See Also enum infinite_timeout = -1 ; The IT_TimedOneshot class includes the symbolic constant infinite_timeout. This constant has a value of -1. IT_TimedOneshot::wait() Orbix TS Thread Library Reference 49

56 IT_TimedOneshot::IT_TimedOneshot() Constructor IT_TimedOneshot( Initializes the one-shot to the RESET state. IT_TimedOneshot::~IT_TimedOneshot() Destructor ~IT_TimedOneshot( Destroys the one-shot object. IT_TimedOneshot::reset() void reset( Resets the one-shot object. Resetting a one-shot while in the SIGNALED state changes its state to RESET. Resetting a one-shot while in the RESET state has no effect. Resetting a one-shot in the WAIT state is an error. Note that this error is not always detected, even in the checked mode. IT_TimedOneshot::signal() void signal( Signals the one-shot. Signaling a one-shot while in the RESET state changes its state to SIGNALED. 50 Orbix TS Thread Library Reference

57 Signaling a one-shot while in the WAIT state atomically releases the waiting thread and changes the one-shot state to RESET. Signaling a one-shot while in the SIGNALED state is an error. IT_TimedOneshot::trywait() int trywait( Equivalent to a call to wait(0, ). See Also IT_TimedOneshot::wait() IT_TimedOneshot::wait() void wait( int wait( long timeout, Waits for the one-shot. Waiting for a one-shot while in the RESET state changes its state to WAIT. the second method returns 1 when another thread signals the one-shot within the time-out period. Otherwise it returns 0 and changes the state back to RESET. Waiting for a one-shot while in the SIGNALED state changes its state to RESET. The first method returns immediately and the second method returns 1 immediately. Waiting for a one-shot while in the WAIT state is an error. timeout The number of milliseconds before the call gives up. You can use the constant infinite_timeout. See Also IT_Semaphore IT_TimedSemaphore Orbix TS Thread Library Reference 51

58 52 Orbix TS Thread Library Reference

59 IT_TimedSemaphore Class The IT_TimedSemaphore object is a counter with a timer for coordinating access to some resources. class IT_TS_API IT_TimedSemaphore public: enum infinite_timeout = -1 ; IT_TimedSemaphore( size_t initial_count, ~IT_TimedSemaphore( void post( void wait( int wait( long timeout, int trywait( private:... ; IT_TimedSemaphore::infinite_timeout Constant See Also enum infinite_timeout = -1 ; The IT_TimedSemaphore class includes the symbolic constant infinite_timeout. This constant has a value of -1. IT_TimedSemaphore::wait() IT_TimedSemaphore::IT_TimedSemaphore() Constructor IT_TimedSemaphore( size_t initial_count, A semaphore constructor. Orbix TS Thread Library Reference 53

60 initial_count Initializes the semaphore s counter with this value. Exceptions An error that can be reported is IT_TSRuntime. IT_TimedSemaphore::~IT_TimedSemaphore() Destructor ~IT_TimedSemaphore( The destructor. IT_TimedSemaphore::post() void post( Exceptions An error that can be reported is IT_TSRuntime. IT_TimedSemaphore::trywait() int trywait( Returns 1 if a resource has been obtained, 0 otherwise. Exceptions An error that can be reported is IT_TSRuntime. IT_TimedSemaphore::wait() void wait(] int wait( long timeout, 54 Orbix TS Thread Library Reference

61 Waits for one resource. The wait() method blocks if the semaphore s counter value is 0 and decrements the counter if the counter s value is greater than 0. timeout The number of milliseconds before the call gives up. You can also use the constant infinite_timeout. Exceptions Errors that can be reported include: IT_TSRuntime IT_TSLogic Orbix TS Thread Library Reference 55

62 56 Orbix TS Thread Library Reference

63 IT_TSBadAlloc Error Class See Also When new() returns 0 an IT_TSBadAlloc exception is reported. class IT_TS_API IT_TSBadAlloc : public IT_TSRuntime public: IT_TSBadAlloc( virtual ~IT_TSBadAlloc( virtual void raise() const; ; IT_TSRuntime IT_TSError Orbix TS Thread Library Reference 57

64 58 Orbix TS Thread Library Reference

65 IT_TSError Error Class All errors reported by the TS package are IT_TSError objects. The key members of the class are as follows: class IT_TS_API IT_TSError public: IT_TSError( unsigned long TS_errcode, long OS_errno = 0 IT_TSError( const IT_TSError& other virtual ~IT_TSError( unsigned long TS_error_code() const; long OS_error_number() const; const char* what() const; virtual void raise() const; See Also protected:... IT_DefaultTSErrorHandler IT_TSError::IT_TSError() Constructors IT_TSError( unsigned long TS_errcode, long OS_errno = 0 IT_TSError( const IT_TSError& other Constructs an error with this TS error code and optionally an error number given by the operating system. The second method is the copy constructor. IT_TSError::~IT_TSError() Destructor virtual ~IT_TSError( The destructor. IT_TSError::OS_error_number() long OS_error_number() const; Returns the operating system error number that represent the error. Returns 0 if the error is not reported by the operating system. Orbix TS Thread Library Reference 59

66 IT_TSError::raise() virtual void raise() const; When exceptions are supported, this method throws *this, a pointer to this IT_TSError object. If exceptions are not supported, it calls ::abort(). IT_TSError::TS_error_code() unsigned long TS_error_code() const; Returns the TS error code that represents the error. IT_TSError::what() See Also const char* what( Returns a string describing the error. The caller must not de-allocate the returned string. IT_TSLogic IT_TSRuntime IT_TSBadAlloc 60 Orbix TS Thread Library Reference

67 IT_TSErrorHandler Class The last parameter of almost every TS method is a reference to an object of the class IT_TSErrorHandler. When a TS method detects an error, it creates an IT_TSError object and passes it to IT_TSErrorHandler::handle(). class IT_TS_API IT_TSErrorHandler public: virtual ~IT_TSErrorHandler( See Also ; virtual void handle( const IT_TSError& thiserror ) = 0; IT_DefaultTSErrorHandler IT_TSErrorHandler::handle() virtual void handle( const IT_TSError& thiserror ) = 0; Handles the given TS error. thiserror The error raised. IT_TSErrorHandler::~IT_TSErrorHandler() Destructor virtual ~IT_TSErrorHandler( The destructor for the error handler object. Orbix TS Thread Library Reference 61

68 62 Orbix TS Thread Library Reference

69 IT_TSLogic Error Class An IT_TSLogic error signals an error in the application s logic, for example when a thread attempts to join itself. class IT_TS_API IT_TSLogic : public IT_TSError public: IT_TSLogic( unsigned long code, long fromos =0 virtual ~IT_TSLogic( virtual void raise() const; See Also private: //... ; IT_TSError IT_TSRuntime Orbix TS Thread Library Reference 63

70 64 Orbix TS Thread Library Reference

71 IT_TSRuntime Error Class An IT_TSRuntime error is an error detected by the operating system or by the underlying thread package. class IT_TS_API IT_TSRuntime : public IT_TSError public: IT_TSRuntime( unsigned long code, long fromos =0 virtual ~IT_TSRuntime( virtual void raise() const; See Also private:... IT_TSError IT_TSRuntime Orbix TS Thread Library Reference 65

72 66 Orbix TS Thread Library Reference

73 IT_TSVoidStar Class An IT_TSVoidStar object is a data entry point that can be shared by multiple threads. Each thread can use this entry point to get and set a void* pointer that refers to thread-specific (private) data. class IT_TSVoidStar public: IT_TSVoidStar( void (*destructor)(void*) df, ~IT_TSVoidStar( void* get( ) const; void set( void* newvalue, private:... ; IT_TSVoidStar::IT_TSVoidStar() Constructor IT_TSVoidStar( void (*destructor)(void*) df, Constructs an IT_TSVoidStar object. Initially, all thread-specific pointers are NULL. df You can optionally associate a non-null destructor method with an IT_TSVoidStar object. Before exiting, a thread will call this destructor with its specific pointer value only when its specific pointer value is not NULL. Exceptions See Also On some platforms, when threads are not started using an IT_ThreadBody, the application might have to call explicitly IT_CurrentThread::cleanup() upon thread exit to perform this cleanup. An error that can be reported is IT_TSRuntime. IT_TSVoidStar::~IT_TSVoidStar() IT_CurrentThread::cleanup() Orbix TS Thread Library Reference 67

74 IT_TSVoidStar::~IT_TSVoidStar() Destructor ~IT_TSVoidStar( The destructor for an IT_TSVoidStar object. If a non-null destructor method is associated with this IT_TSVoidStar object (by way of the IT_TSVoidStar() constructor), and the thread-specific value of this object is not NULL, the non-null destructor method is called with the thread-specific value. WARNING: If the IT_TSVoidStar object has a non-null destructor, do not destroy the object while any other threads have a non-null thread-specific pointer. This is because on some platforms, a newly allocated IT_TSVoidStar object might reincarnate the destroyed IT_TSVoidStar object and its thread-specific values. This can lead to unexpected results. See Also IT_TSVoidStar::IT_TSVoidStar() IT_TSVoidStar::get() void* get( ) const; Gets the pointer associated with the calling thread. Returns NULL when the calling thread did not explicitly set this value. Exceptions An error that can be reported is IT_TSRuntime. IT_TSVoidStar::set() void set( void* newvalue, Sets the pointer associated with the calling thread to newvalue. Exceptions An error that can be reported is IT_TSRuntime. 68 Orbix TS Thread Library Reference

75 Index B broadcast() 7 C cancel() 16, 28 cleanup() 9 close() 13 D DetachState enumeration 43 G get() 68 H handle() 11, 61 I id() 9, 37 infinite_size constant 45 infinite_timeout constant 46, 49, 53 is_locked() 16 is_main_thread() 9 is_null() 38 ~IT_Condition() 8 IT_Condition() constructor 7 IT_Condition class 7 IT_CurrentThread class 9 ~IT_DefaultTSErrorHandler() 11 IT_DefaultTSErrorHandler class 11 ~IT_Gateway() 14 IT_Gateway() constructor 13 IT_Gateway class 13 ~IT_Locker() 17 IT_Locker() 17 IT_Locker Template class 15 ~IT_Mutex() 20 IT_Mutex() constructor 19 IT_Mutex class 19 IT_PODMutex Structure 21 ~IT_RecursiveMutex() 24 IT_RecursiveMutex() constructor 23 IT_RecursiveMutex class 23 ~IT_RecursiveMutexLocker() 29 IT_RecursiveMutexLocker() constructors 29 IT_RecursiveMutexLocker class 27 ~IT_Semaphore() 33 IT_Semaphore() constructor 33 IT_Semaphore class 33 IT_TerminationHandler class 35 ~IT_Thread() 38 IT_Thread() constructors 38 ~IT_ThreadBody() 41 IT_ThreadBody class 41 IT_Thread class 37 ~IT_ThreadFactory() 44 IT_ThreadFactory() constructor 43 IT_ThreadFactory class 43 ~IT_TimedCountByNSemaphore() 46 IT_TimedCountByNSemaphore() constructor 46 IT_TimedCountByNSemaphore class 45 ~IT_TimedOneshot() 50 IT_TimedOneshot() constructor 50 IT_TimedOneshot class 49 ~IT_TimedSemaphore() 54 IT_TimedSemaphore() constructor 53 IT_TimedSemaphore class 53 IT_TSBadAlloc error class 57 ~IT_TSError() 59 IT_TSError() constructors 59 IT_TSError error class 59 ~IT_TSErrorHandler() 61 IT_TSErrorHandler class 61 IT_TSLogic error class 63 IT_TSRuntime error class 65 ~IT_TSVoidStar() 68 IT_TSVoidStar() constructor 67 IT_TSVoidStar class 67 J join() 38 L lock() 18, 20, 21, 24, 30 lock_count() 30 M m_index data type 21 mutex() 18, 30 O open() 14 operator!=() 39 operator=() 39 operator==() 39 OS_error_number() 59 P post() 34, 46, 54 R raise() 60 Orbix TS Thread Library Reference 69

TS Thread Library Reference. Version 6.2, December 2004

TS Thread Library Reference. Version 6.2, December 2004 TS Thread Library Reference Version 6.2, December 2004 IONA, IONA Technologies, the IONA logo, Orbix, Orbix/E, Orbacus, Artix, Orchestrator, Mobile Orchestrator, Enterprise Integrator, Adaptive Runtime

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

The OMNI Thread Abstraction

The OMNI Thread Abstraction The OMNI Thread Abstraction Tristan Richardson AT&T Laboratories Cambridge Revised November 2001 1 Introduction The OMNI thread abstraction is designed to provide a common set of thread operations for

More information

Concurrency, Thread. Dongkun Shin, SKKU

Concurrency, Thread. Dongkun Shin, SKKU Concurrency, Thread 1 Thread Classic view a single point of execution within a program a single PC where instructions are being fetched from and executed), Multi-threaded program Has more than one point

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 9 Initializing a non-static data member in the class definition is a syntax error 1 9.2 Time Class Case Study In Fig. 9.1, the class definition is enclosed in the following

More information

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [THREADS] Frequently asked questions from the previous class survey

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [THREADS] Frequently asked questions from the previous class survey CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [THREADS] Threads block when they can t get that lock Wanna have your threads stall? Go ahead, synchronize it all The antidote to this liveness pitfall? Keeping

More information

Synchronization SPL/2010 SPL/20 1

Synchronization SPL/2010 SPL/20 1 Synchronization 1 Overview synchronization mechanisms in modern RTEs concurrency issues places where synchronization is needed structural ways (design patterns) for exclusive access 2 Overview synchronization

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

Concurrency: a crash course

Concurrency: a crash course Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Concurrency: a crash course Concurrent computing Applications designed as a collection of computational units that may execute

More information

Real Time Operating Systems and Middleware

Real Time Operating Systems and Middleware Real Time Operating Systems and Middleware POSIX Threads Synchronization Luca Abeni abeni@dit.unitn.it Real Time Operating Systems and Middleware p. 1 Threads Synchronisation All the threads running in

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 The Process Concept 2 The Process Concept Process a program in execution

More information

SmartHeap for Multi-Core

SmartHeap for Multi-Core SmartHeap for Multi-Core Getting Started and Platform Guide for Linux Version 11.2 SmartHeap and HeapAgent are trademarks of Compuware Corporation. All other trademarks are the property of their respective

More information

Concurrent Programming using Threads

Concurrent Programming using Threads Concurrent Programming using Threads Threads are a control mechanism that enable you to write concurrent programs. You can think of a thread in an object-oriented language as a special kind of system object

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

The University of Texas at Arlington

The University of Texas at Arlington The University of Texas at Arlington Lecture 10: Threading and Parallel Programming Constraints CSE 5343/4342 Embedded d Systems II Objectives: Lab 3: Windows Threads (win32 threading API) Convert serial

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),

More information

POSIX Threads. Paolo Burgio

POSIX Threads. Paolo Burgio POSIX Threads Paolo Burgio paolo.burgio@unimore.it The POSIX IEEE standard Specifies an operating system interface similar to most UNIX systems It extends the C language with primitives that allows the

More information

Lecture 8: September 30

Lecture 8: September 30 CMPSCI 377 Operating Systems Fall 2013 Lecture 8: September 30 Lecturer: Prashant Shenoy Scribe: Armand Halbert 8.1 Semaphores A semaphore is a more generalized form of a lock that can be used to regulate

More information

ArdOS The Arduino Operating System Reference Guide Contents

ArdOS The Arduino Operating System Reference Guide Contents ArdOS The Arduino Operating System Reference Guide Contents 1. Introduction... 2 2. Error Handling... 2 3. Initialization and Startup... 2 3.1 Initializing and Starting ArdOS... 2 4. Task Creation... 3

More information

Orbacus Version JThreads/C++ Guide

Orbacus Version JThreads/C++ Guide Orbacus Version 4.3.5 JThreads/C++ Guide Micro Focus The Lawn 22-30 Old Bath Road Newbury, Berkshire RG14 1QN UK http://www.microfocus.com Copyright Micro Focus 2016. All rights reserved. MICRO FOCUS,

More information

Operating Systems, Assignment 2 Threads and Synchronization

Operating Systems, Assignment 2 Threads and Synchronization Operating Systems, Assignment 2 Threads and Synchronization Responsible TA's: Zohar and Matan Assignment overview The assignment consists of the following parts: 1) Kernel-level threads package 2) Synchronization

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1. COMP6771 Advanced C++ Programming Week 9 Multithreading (continued) 2016 www.cse.unsw.edu.au/ cs6771 2. So Far Program Workflows: Sequential, Parallel, Embarrassingly Parallel Memory: Shared Memory,

More information

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other No efficient solution Involve conflicting

More information

C++ (Non for C Programmer) (BT307) 40 Hours

C++ (Non for C Programmer) (BT307) 40 Hours C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular

More information

Synchronising Threads

Synchronising Threads Synchronising Threads David Chisnall March 1, 2011 First Rule for Maintainable Concurrent Code No data may be both mutable and aliased Harder Problems Data is shared and mutable Access to it must be protected

More information

Locks. Dongkun Shin, SKKU

Locks. Dongkun Shin, SKKU Locks 1 Locks: The Basic Idea To implement a critical section A lock variable must be declared A lock variable holds the state of the lock Available (unlocked, free) Acquired (locked, held) Exactly one

More information

Java Threads. Written by John Bell for CS 342, Spring 2018

Java Threads. Written by John Bell for CS 342, Spring 2018 Java Threads Written by John Bell for CS 342, Spring 2018 Based on chapter 9 of Learning Java, Fourth Edition by Niemeyer and Leuck, and other sources. Processes A process is an instance of a running program.

More information

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture)

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture) Intro to Threads Two approaches to concurrency - Asynchronous I/O (lab) - Threads (today s lecture) Threaded multifinger: - Run many copies of finger simultaneously for (int i = 1; i < argc; i++) thread_create

More information

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem? What is the Race Condition? And what is its solution? Race Condition: Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular

More information

ECE 574 Cluster Computing Lecture 8

ECE 574 Cluster Computing Lecture 8 ECE 574 Cluster Computing Lecture 8 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 16 February 2017 Announcements Too many snow days Posted a video with HW#4 Review HW#5 will

More information

The University of Texas at Arlington

The University of Texas at Arlington The University of Texas at Arlington Lecture 6: Threading and Parallel Programming Constraints CSE 5343/4342 Embedded Systems II Based heavily on slides by Dr. Roger Walker More Task Decomposition: Dependence

More information

Chenyu Zheng. CSCI 5828 Spring 2010 Prof. Kenneth M. Anderson University of Colorado at Boulder

Chenyu Zheng. CSCI 5828 Spring 2010 Prof. Kenneth M. Anderson University of Colorado at Boulder Chenyu Zheng CSCI 5828 Spring 2010 Prof. Kenneth M. Anderson University of Colorado at Boulder Actuality Introduction Concurrency framework in the 2010 new C++ standard History of multi-threading in C++

More information

Experience with Processes and Monitors in Mesa. Arvind Krishnamurthy

Experience with Processes and Monitors in Mesa. Arvind Krishnamurthy Experience with Processes and Monitors in Mesa Arvind Krishnamurthy Background Focus of this paper: light-weight processes (threads) and how they synchronize with each other History: Second system; followed

More information

EMBEDDED SYSTEMS PROGRAMMING More About Languages

EMBEDDED SYSTEMS PROGRAMMING More About Languages EMBEDDED SYSTEMS PROGRAMMING 2015-16 More About Languages JAVA: ANNOTATIONS (1/2) Structured comments to source code (=metadata). They provide data about the code, but they are not part of the code itself

More information

VisiBroker Release Notes

VisiBroker Release Notes VisiBroker 8.5.2 Release Notes Micro Focus The Lawn 22-30 Old Bath Road Newbury, Berkshire RG14 1QN UK http://www.microfocus.com Copyright Micro Focus 2015. All rights reserved. VisiBroker contains derivative

More information

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid.

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid. Threads Dr. Ayman Abdel-Hamid, CS4254 Spring 2006 1 CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department Virginia Tech Threads Outline Threads (Chapter

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

Concurrent Server Design Multiple- vs. Single-Thread

Concurrent Server Design Multiple- vs. Single-Thread Concurrent Server Design Multiple- vs. Single-Thread Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN NTUT, TAIWAN 1 Examples Using

More information

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007 CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Threads and Synchronization May 8, 2007 Computation Abstractions t1 t1 t4 t2 t1 t2 t5 t3 p1 p2 p3 p4 CPU 1 CPU 2 A computer Processes

More information

Concurrency: Deadlock and Starvation

Concurrency: Deadlock and Starvation Concurrency: Deadlock and Starvation Chapter 6 E&CE 354: Processes 1 Deadlock Deadlock = situation in which every process from a set is permanently blocked, i.e. cannot proceed with execution Common cause:

More information

OPERATING SYSTEMS ASSIGNMENT 2 SIGNALS, USER LEVEL THREADS AND SYNCHRONIZATION

OPERATING SYSTEMS ASSIGNMENT 2 SIGNALS, USER LEVEL THREADS AND SYNCHRONIZATION OPERATING SYSTEMS ASSIGNMENT 2 SIGNALS, USER LEVEL THREADS AND SYNCHRONIZATION Responsible TAs: Vadim Levit & Benny Lutati Introduction In this assignment we will extend xv6 to support a simple signal

More information

Ch. 11: References & the Copy-Constructor. - continued -

Ch. 11: References & the Copy-Constructor. - continued - Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

Vector and Free Store (Pointers and Memory Allocation)

Vector and Free Store (Pointers and Memory Allocation) DM560 Introduction to Programming in C++ Vector and Free Store (Pointers and Memory Allocation) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides

More information

Checkpoint/Restart System Services Interface (SSI) Modules for LAM/MPI API Version / SSI Version 1.0.0

Checkpoint/Restart System Services Interface (SSI) Modules for LAM/MPI API Version / SSI Version 1.0.0 Checkpoint/Restart System Services Interface (SSI) Modules for LAM/MPI API Version 1.0.0 / SSI Version 1.0.0 Sriram Sankaran Jeffrey M. Squyres Brian Barrett Andrew Lumsdaine http://www.lam-mpi.org/ Open

More information

Introduction to OS Synchronization MOS 2.3

Introduction to OS Synchronization MOS 2.3 Introduction to OS Synchronization MOS 2.3 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Challenge How can we help processes synchronize with each other? E.g., how

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Multithreading Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to large compute clusters Can perform multiple

More information

Orbix Release Notes

Orbix Release Notes Contents Orbix 2.3.4 Release Notes September 1999 Introduction 2 Development Environments 2 Solaris 2 Year 2000 Compliance 2 Solaris 2.5.1 Y2K Patches 3 NT 3 Compatibility with Other IONA Products 4 New

More information

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico. Java Monitors Parallel and Distributed Computing Department of Computer Science and Engineering (DEI) Instituto Superior Técnico October 19, 2010 Monteiro, Costa (DEI / IST) Parallel and Distributed Computing

More information

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts. CPSC/ECE 3220 Fall 2017 Exam 1 Name: 1. Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.) Referee / Illusionist / Glue. Circle only one of R, I, or G.

More information

VisiBroker for Visual Studio 2013

VisiBroker for Visual Studio 2013 VisiBroker 8.5.2 for Visual Studio 2013 Release Notes Micro Focus The Lawn 22-30 Old Bath Road Newbury, Berkshire RG14 1QN UK http://www.microfocus.com Copyright Micro Focus 2015. All rights reserved.

More information

Programming in Parallel COMP755

Programming in Parallel COMP755 Programming in Parallel COMP755 All games have morals; and the game of Snakes and Ladders captures, as no other activity can hope to do, the eternal truth that for every ladder you hope to climb, a snake

More information

Efficient concurrent waiting for C++20

Efficient concurrent waiting for C++20 Doc number: P0514R3 Revises: P0514R2, P0126R2, N4195 Date: 2018-02-10 Project: Programming Language C++, Concurrency Working Group Reply-to: Olivier Giroux Efficient concurrent waiting

More information

TCSS 422: OPERATING SYSTEMS

TCSS 422: OPERATING SYSTEMS TCSS 422: OPERATING SYSTEMS OBJECTIVES Introduction to threads Concurrency: An Introduction Wes J. Lloyd Institute of Technology University of Washington - Tacoma Race condition Critical section Thread

More information

Module 1. Introduction:

Module 1. Introduction: Module 1 Introduction: Operating system is the most fundamental of all the system programs. It is a layer of software on top of the hardware which constitutes the system and manages all parts of the system.

More information

Deadlock. Lecture 4: Synchronization & Communication - Part 2. Necessary conditions. Deadlock handling. Hierarchical resource allocation

Deadlock. Lecture 4: Synchronization & Communication - Part 2. Necessary conditions. Deadlock handling. Hierarchical resource allocation Lecture 4: Synchronization & ommunication - Part 2 [RTS h 4] Deadlock Priority Inversion & Inheritance Mailbox ommunication ommunication with Objects Deadlock Improper allocation of common resources may

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

A Cooperatively Interruptible Joining Thread, Rev 4 New in R4

A Cooperatively Interruptible Joining Thread, Rev 4 New in R4 Project: ISO JTC1/SC22/WG21: Programming Language C++ Doc No: WG21 Date: 2018-09-11 Reply to: Nicolai Josuttis (nico@josuttis.de), Herb Sutter (hsutter@microsoft.com), Anthony Williams (anthony@justsoftwaresolutions.co.uk)

More information

int result; int waitstat; int stat = PmcaAsyncGetGain(&result); // stat receives request id

int result; int waitstat; int stat = PmcaAsyncGetGain(&result); // stat receives request id PMCA COM API Programmer's Guide PMCA COM is an Application Programming Interface Library for the Amptek Pocket Multichannel Analyzers MCA8000 and MCA8000A. PMCA COM runs on personal computers under any

More information

Remaining Contemplation Questions

Remaining Contemplation Questions Process Synchronisation Remaining Contemplation Questions 1. The first known correct software solution to the critical-section problem for two processes was developed by Dekker. The two processes, P0 and

More information

Virtual Machine Design

Virtual Machine Design Virtual Machine Design Lecture 4: Multithreading and Synchronization Antero Taivalsaari September 2003 Session #2026: J2MEPlatform, Connected Limited Device Configuration (CLDC) Lecture Goals Give an overview

More information

Financial computing with C++

Financial computing with C++ Financial Computing with C++, Lecture 6 - p1/24 Financial computing with C++ LG Gyurkó University of Oxford Michaelmas Term 2015 Financial Computing with C++, Lecture 6 - p2/24 Outline Linked lists Linked

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008. CSC 4103 - Operating Systems Spring 2008 Lecture - XII Midterm Review Tevfik Ko!ar Louisiana State University March 4 th, 2008 1 I/O Structure After I/O starts, control returns to user program only upon

More information

Java Threads and intrinsic locks

Java Threads and intrinsic locks Java Threads and intrinsic locks 1. Java and OOP background fundamentals 1.1. Objects, methods and data One significant advantage of OOP (object oriented programming) is data encapsulation. Each object

More information

real time operating systems course

real time operating systems course real time operating systems course 4 introduction to POSIX pthread programming introduction thread creation, join, end thread scheduling thread cancellation semaphores thread mutexes and condition variables

More information

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Objectives To introduce the notion of a

More information

27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads?

27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads? Objectives MultiThreading What are Threads? Interrupting threads Thread properties By Võ Văn Hải Faculty of Information Technologies Summer 2012 Threads priorities Synchronization Callables and Futures

More information

A jthread automatically signals an interrupt at the end of its lifetime to the started thread (if still joinable) and joins:

A jthread automatically signals an interrupt at the end of its lifetime to the started thread (if still joinable) and joins: Project: ISO JTC1/SC22/WG21: Programming Language C++ Doc No: WG21 Date: 2018-10-06 Reply to: Nicolai Josuttis (nico@josuttis.de), Herb Sutter (hsutter@microsoft.com), Anthony Williams (anthony@justsoftwaresolutions.co.uk)

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

1 Introduction. 2 Managing contexts. Green, green threads of home. Johan Montelius HT2018

1 Introduction. 2 Managing contexts. Green, green threads of home. Johan Montelius HT2018 1 Introduction Green, green threads of home Johan Montelius HT2018 This is an assignment where you will implement your own thread library. Instead of using the operating systems threads you will create

More information

Proposed Wording for Concurrent Data Structures: Hazard Pointer and Read Copy Update (RCU)

Proposed Wording for Concurrent Data Structures: Hazard Pointer and Read Copy Update (RCU) Document number: D0566R1 Date: 20170619 (pre Toronto) Project: Programming Language C++, WG21, SG1,SG14, LEWG, LWG Authors: Michael Wong, Maged M. Michael, Paul McKenney, Geoffrey Romer, Andrew Hunter

More information

Pre-lab #2 tutorial. ECE 254 Operating Systems and Systems Programming. May 24, 2012

Pre-lab #2 tutorial. ECE 254 Operating Systems and Systems Programming. May 24, 2012 Pre-lab #2 tutorial ECE 254 Operating Systems and Systems Programming May 24, 2012 Content Concurrency Concurrent Programming Thread vs. Process POSIX Threads Synchronization and Critical Sections Mutexes

More information

EECS 482 Introduction to Operating Systems

EECS 482 Introduction to Operating Systems EECS 482 Introduction to Operating Systems Winter 2018 Harsha V. Madhyastha Monitors vs. Semaphores Monitors: Custom user-defined conditions Developer must control access to variables Semaphores: Access

More information

High Performance Computing Course Notes Shared Memory Parallel Programming

High Performance Computing Course Notes Shared Memory Parallel Programming High Performance Computing Course Notes 2009-2010 2010 Shared Memory Parallel Programming Techniques Multiprocessing User space multithreading Operating system-supported (or kernel) multithreading Distributed

More information

Chapter 6 Process Synchronization

Chapter 6 Process Synchronization Chapter 6 Process Synchronization Cooperating Process process that can affect or be affected by other processes directly share a logical address space (threads) be allowed to share data via files or messages

More information

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07 Informatica 3 Marcello Restelli 9/15/07 10/29/07 Laurea in Ingegneria Informatica Politecnico di Milano Structuring the Computation Control flow can be obtained through control structure at instruction

More information

JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling

JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling Multithreaded Programming Topics Multi Threaded Programming What are threads? How to make the classes threadable; Extending threads;

More information

Synchronization for Concurrent Tasks

Synchronization for Concurrent Tasks Synchronization for Concurrent Tasks Minsoo Ryu Department of Computer Science and Engineering 2 1 Race Condition and Critical Section Page X 2 Algorithmic Approaches Page X 3 Hardware Support Page X 4

More information

EL6483: Brief Overview of C Programming Language

EL6483: Brief Overview of C Programming Language EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Concurrent Programming

Concurrent Programming Concurrency Concurrent Programming A sequential program has a single thread of control. Its execution is called a process. A concurrent program has multiple threads of control. They may be executed as

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

Unlike the methods of all other objects in the MPI, Control object methods are not thread-safe. Error Messages

Unlike the methods of all other objects in the MPI, Control object methods are not thread-safe. Error Messages Control Objects Control Objects Introduction A Control object manages a motion controller device. The device is typically a single board residing in a PC or an embedded system. A control object can read

More information

Orbacus. JThreads/C++ Making Software Work Together TM. Version 2.0, January 2007

Orbacus. JThreads/C++ Making Software Work Together TM. Version 2.0, January 2007 TM Orbacus JThreads/C++ Version 2.0, January 2007 Making Software Work Together TM IONA Technologies PLC and/or its subsidiaries may have patents, patent applications, trademarks, copyrights, or other

More information

Unix System Programming - Chapter 2, part a

Unix System Programming - Chapter 2, part a Unix System Programming - Chapter 2, part a Neal Nelson The Evergreen State College Mar 23, 2010 USP Chapter 2.1 to 2.6 Processes and Threads Program Storage and Linkage Library Function Calls Error Handling

More information

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 Lecture 8: Semaphores, Monitors, & Condition Variables 8.0 Main Points: Definition of semaphores Example of use

More information

CS355 Hw 4. Interface. Due by the end of day Tuesday, March 20.

CS355 Hw 4. Interface. Due by the end of day Tuesday, March 20. Due by the end of day Tuesday, March 20. CS355 Hw 4 User-level Threads You will write a library to support multiple threads within a single Linux process. This is a user-level thread library because the

More information

What's wrong with Semaphores?

What's wrong with Semaphores? Next: Monitors and Condition Variables What is wrong with semaphores? Monitors What are they? How do we implement monitors? Two types of monitors: Mesa and Hoare Compare semaphore and monitors Lecture

More information

Quadros. RTXC Kernel Services Reference, Volume 1. Levels, Threads, Exceptions, Pipes, Event Sources, Counters, and Alarms. Systems Inc.

Quadros. RTXC Kernel Services Reference, Volume 1. Levels, Threads, Exceptions, Pipes, Event Sources, Counters, and Alarms. Systems Inc. Quadros Systems Inc. RTXC Kernel Services Reference, Volume 1 Levels, Threads, Exceptions, Pipes, Event Sources, Counters, and Alarms Disclaimer Quadros Systems, Inc. makes no representations or warranties

More information

C++ for System Developers with Design Pattern

C++ for System Developers with Design Pattern C++ for System Developers with Design Pattern Introduction: This course introduces the C++ language for use on real time and embedded applications. The first part of the course focuses on the language

More information

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course Advanced Java Programming Course MultiThreading By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Session objectives Introduction Creating thread Thread class

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 11: Semaphores I" Brian Logan School of Computer Science bsl@cs.nott.ac.uk Outline of this lecture" problems with Peterson s algorithm semaphores implementing semaphores

More information

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Advanced Java Programming Course MultiThreading By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Session objectives Introduction Creating thread Thread class

More information

Threads Tuesday, September 28, :37 AM

Threads Tuesday, September 28, :37 AM Threads_and_fabrics Page 1 Threads Tuesday, September 28, 2004 10:37 AM Threads A process includes an execution context containing Memory map PC and register values. Switching between memory maps can take

More information

Recap. Contents. Reenterancy of synchronized. Explicit Locks: ReentrantLock. Reenterancy of synchronise (ctd) Advanced Thread programming.

Recap. Contents. Reenterancy of synchronized. Explicit Locks: ReentrantLock. Reenterancy of synchronise (ctd) Advanced Thread programming. Lecture 07: Advanced Thread programming Software System Components 2 Behzad Bordbar School of Computer Science, University of Birmingham, UK Recap How to deal with race condition in Java Using synchronised

More information