File: Thread.inc

package info (click to toggle)
skypat 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 664 kB
  • sloc: cpp: 2,545; makefile: 220; ansic: 78; sh: 67
file content (44 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//===- Thread.inc ---------------------------------------------------------===//
//
//                              The SkyPat team 
//
// This file is distributed under the New BSD License.
// See LICENSE for details.
//
//===----------------------------------------------------------------------===//
#include <iostream>
#include <pthread.h>

//===----------------------------------------------------------------------===//
// Thread
//===----------------------------------------------------------------------===//
void Thread::start()
{
  pthread_attr_t attr;
  pthread_attr_init(&attr);

  // TODO: set up attributes

  // create a thread
  int code =
      pthread_create(&m_pThreadImpl->thread_id, &attr, ThreadImpl::start, this);
  if (0 != code) {
    std::cerr << code;
  }

  pthread_attr_destroy(&attr);
}

bool Thread::join()
{
  // TODO: can not wait on itself
  // TODO: if the thread is finished or not running, then return false
  // TODO: pthread_join, then return code.
  void* status;
  int code = pthread_join(impl()->thread_id, &status);
  if (0 != code) {
    std::cerr << code;
    return false;
  }
  return true;
}