DCL 3.7.4
Loading...
Searching...
No Matches
Thread Class Referenceabstract

#include <Thread.h>

Inheritance diagram for Thread:
Object PollThread

Classes

class  CondVar
class  Event
class  Mutex
class  SingleLock

Public Types

typedef void(* initRoutine) ()
typedef SingleLock< MutexSingleLockMutex
typedef SingleLock< SpinLock > SingleLockSpin

Static Public Member Functions

static void sleep (unsigned int _mills)
static void yield ()
static thread_t self ()
static ThreadgetSelfThread ()
static void crtLock (const void *_p)
static void crtUnlock (const void *_p)
static long incrementAndGet (volatile long &_n)
static long long incrementAndGet (volatile long long &_n)
static long decrementAndGet (volatile long &_n)
static long long decrementAndGet (volatile long long &_n)

Protected Member Functions

virtual bool init ()
virtual int run ()=0
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Additional Inherited Members

Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Detailed Description

Definition at line 54 of file Thread.h.

Member Typedef Documentation

◆ initRoutine

typedef void(* Thread::initRoutine) ()

다중 스레드 환경에서 단일 호출을 위한 제어변스의 타입을 정의한다.

Definition at line 156 of file Thread.h.

◆ SingleLockMutex

Definition at line 411 of file Thread.h.

◆ SingleLockSpin

Definition at line 413 of file Thread.h.

Member Function Documentation

◆ crtLock()

void Thread::crtLock ( const void * _p)
static

다중 스레드 환경에서 _initRoutine의 단일 호출을 보장한다.

사용의 예는 다음과 같다.

      static Thread::OnceType once = Thread::ONCE_INIT;
      static void initRoutine()
      {
        ...
      }

      Thread::once(once, initRoutine);
 */
static void once(thread_once_t& _onceControl, initRoutine _initRoutine);

/**
   스레드 전용 지억장소를 위한 키를 생성한다.
   
UNIX는 pthread_key_create, Windows는 TlsAlloc을 사용한다.
   
Exceptions
SysError*키 생성이 실패하면 예외가 던져지며, 사유는 다음과 같다.
  • UNIX - 키생성에 PTHREAD_KEYS_MAX에 도달했거나 메모리가 부족한 경우이다.
  • Windows - TlsAlloc이 TLS_OUT_OF_INDEXES을 반환했다.
*/ static thread_key_t keyCreate() __DCL_THROWS1(SysError*); /** 스레드 전용 기억장소를 위한 키를 삭제한다
Parameters
_keykeyCreate로 반환된 값.
Exceptions
SysError*_key가 유효하지 않으면 예외가 던져진다. */ static void keyDelete(thread_key_t _key) __DCL_THROWS1(SysError*); /** 호출 스레드 전용 기억장소에 값을 설정한다.
Parameters
_keykeyCreate로 반환된 값.
Exceptions
SysError*_key가 유효하지 않으면 예외가 던져진다. */ static void keySetValue(thread_key_t _key, void* _value) __DCL_THROWS1(SysError*); /** 호출 스레드 전용 기억장소의 값을 리턴한다.
Parameters
_keykeyCreate로 반환된 값.
Returns
값이 설정되어 있지 않으면 NULL을 반환한다.
Exceptions
SysError*_key가 유효하지 않으면 예외가 던져진다. */ static void* keyGetValue(thread_key_t _key) __DCL_THROWS1(SysError*); /** C 런타임이 다중 스레드에 안전하지 않으면 이것을 사용하여 동기화 한다.
crtLock을 호출하면 반드시 이 후에 crtUnlock을 호출 해야만 한다.
   
example
   
   char a[100];
   time_t now = time(NULL);
   Thread::crtLock(&now);
   char* cp = ctime(&now);
   strcpy(a, cp);
   Thread::crtUnlock(&now);
   

Definition at line 269 of file Thread.cpp.

270{
271 __lock_t& lock = __lock[(size_t) _p % __LOCK_COUNT];
272 __lock(lock);
273}
#define __LOCK_COUNT
Definition Thread.cpp:266

◆ crtUnlock()

void Thread::crtUnlock ( const void * _p)
static

Definition at line 275 of file Thread.cpp.

276{
277 __lock_t& lock = __lock[(size_t) _p % __LOCK_COUNT];
278 __unlock(lock);
279}

◆ decrementAndGet() [1/2]

long Thread::decrementAndGet ( volatile long & _n)
static

◆ decrementAndGet() [2/2]

long long Thread::decrementAndGet ( volatile long long & _n)
static

◆ getSelfThread()

Thread * Thread::getSelfThread ( )
static

호출한 스레드의 객체를 반환한다.

이 메소드는 스레드 생성 후 init()에서 스레드 전용 기억장소에 설정한 것의 반환값이다. 따라서, init()이 호출되지 않으면 NULL을 리턴한다.

Definition at line 104 of file Thread.cpp.

105{
106 __DCL_ASSERT(__keySelfThread != (__key_t)-1);
107 return (Thread*) __key_get(__keySelfThread);
108}
#define __DCL_ASSERT(expr)
Definition Object.h:394

◆ incrementAndGet() [1/2]

long Thread::incrementAndGet ( volatile long & _n)
static

◆ incrementAndGet() [2/2]

long long Thread::incrementAndGet ( volatile long long & _n)
static

◆ init()

bool Thread::init ( )
protectedvirtual

스레드 객체를 초기화한다.

이 메소드는 start()에 의해 생성된 스레드 내에서 호출된다.

기본 구현은 getSelfThread()을 위해 객체의 포인터를 스레드 전용 기억장소에 설정한다.

See also
#keySetValue
Returns
false를 반환하면 스레드는 즉시 종료되고, run()은 호출되지않고 join()은 -1을 반환한다.

Definition at line 99 of file Thread.cpp.

100{
101 return __key_set_success(__keySelfThread, this);
102}

◆ run()

virtual int Thread::run ( )
protectedpure virtual

스레드의 주 실행 루프를 구현한다.

Implemented in PollThread.

◆ self()

thread_t Thread::self ( )
static

호출한 스레드의 스레드의 ID을 얻는다.

Definition at line 175 of file Thread.cpp.

176{
177#if __DCL_PTHREAD
178 return pthread_self();
179#elif defined(__WINNT__)
180 return GetCurrentThreadId();
181#endif
182}

◆ sleep()

void Thread::sleep ( unsigned int _mills)
static

미리초만큼 스레드의 실행을 중지한다. UNIX 에서 시그널에 인터럽트될 수 있다.

Definition at line 152 of file Thread.cpp.

153{
154#if __DCL_PTHREAD
155 /*
156 ::sleep(_milliseconds / 1000);
157 ::usleep((_milliseconds % 1000) * 1000);
158 */
159 poll(NULL, 0, _mills);
160#elif defined(__WINNT__)
161 Sleep(_mills);
162#endif
163}
#define NULL
Definition Config.h:312

◆ yield()

void Thread::yield ( )
static

CPU를 다른 스레드에 양보한다.

Definition at line 165 of file Thread.cpp.

166{
167#if __DCL_PTHREAD
168 // pthread_yield(); deprecated
169 sched_yield();
170#elif defined(__WINNT__)
171 SwitchToThread();
172#endif
173}

The documentation for this class was generated from the following files: