개발자_이훈규
천천히, 빠르게. 개발자의 Repository
개발자_이훈규
전체 방문자
오늘
어제
  • 분류 전체보기 (473)
    • 티스토리 (4)
    • 개발자 뉴스 (2)
    • 소프트웨어 (203)
      • C (7)
      • c++ (25)
      • Objective-C (3)
      • Do it! 반응형 웹디자인 (4)
      • openGL (8)
      • Java (24)
      • Jni (3)
      • Android (9)
      • Wordpress (2)
      • 버그 만난 후 느낀점 (2)
      • Git (3)
      • node js (2)
      • window tablet (1)
      • HTML (3)
      • javascript (3)
      • perl (1)
      • AngularJS (0)
      • JSON (0)
      • Docker (3)
      • python (5)
      • jQuery (1)
      • MFC (4)
      • cocos studio (6)
      • Golang (1)
      • SQLite3 (0)
      • Spring Boot (8)
      • thymeleaf (0)
      • Django (0)
      • iOS (3)
      • skia (0)
      • VBA (0)
      • PHP (2)
      • Oracle (1)
      • JSP (0)
      • R (0)
    • TCP IP (2)
    • 금융 (0)
      • 금융 Study (0)
      • 금융 Archive (0)
      • 금융 Article (0)
    • 개인 프로젝트 (7)
      • gif 홈페이지 만들기 (0)
      • study app만들기 (0)
      • 크롤러 만들기 (1)
      • 카툰 홈페이지 만들기 (1)
      • 외주 홈페이지 만들기 (3)
      • 웹 홈페이지 만들기 (0)
      • 미디어 서버 만들기 (0)
      • 소개팅 어플 만들기 (0)
      • 인스타그램 풀스택 클론 코딩(인강 노트) (0)
      • 주식 모의거래 만들기 (1)
    • html php mysql (0)
    • node.Js (2)
    • 일상 (2)
    • 빈공간 uml 공부 (0)
    • Ubuntu(linux) (12)
    • 맥OS (10)
      • android 설치하기 (2)
    • Programming quizzes (0)
    • IoT (구 유비쿼터스) (16)
      • 라즈베리 파이 (11)
      • 아두이노 (5)
    • 하드웨어 (5)
      • 아수스 비보탭 노트8 asus vivotap no.. (2)
      • 크레마 카르타 (3)
    • 분석할 문장, 구문, 코드 (0)
    • 키보드 (1)
      • 해피해킹 (1)
    • 코드 라이언 (0)
    • 전자기기 (4)
    • Ted (0)
    • NAS (0)
    • 알고리즘 (0)
    • 연합인포맥스 (0)
    • 이벤트 응모함 (4)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

인기 글

태그

  • Example
  • C
  • 예제
  • 설치
  • 설명
  • Python
  • GIT
  • ubuntu
  • 에러
  • 우분투
  • install
  • error
  • 소스
  • 코드
  • 개발
  • CODE
  • 라즈베리 파이
  • Java
  • 방법
  • C++

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
개발자_이훈규

천천히, 빠르게. 개발자의 Repository

소프트웨어

[c++] thread 기본 구조, 모양

2014. 1. 28. 11:36

1. 

thread에 함수 넣는 부분에 &를 붇이지 않아도 함수 이름이 갖고 있는 해당 메모리 주소로 인식된다는 말을 듣고 해보았지만 에러가 떠서 이것 저것 찾다가 그냥 예시를 찾았다.



2.

#include <cstdio>

#include <string>

#include <iostream>


#include <pthread.h>


void* print(void* data)

{

    std::cout << *((std::string*)data) << "\n";

    return NULL; // We could return data here if we wanted to

}


int main()

{

    std::string message = "Hello, pthreads!";

    pthread_t threadHandle;

    pthread_create(&threadHandle, NULL, &print, &message);

    // Wait for the thread to finish, then exit

    pthread_join(threadHandle, NULL);

    return 0;

}


A better alternative, if you're able to, is to use the new C++11 thread library. It's a simpler, RAII interface that uses templates so that you can pass any function to a thread, including class member functions (see this thread).


Then, the above exmaple simplifies to this:


#include <cstdio>

#include <string>

#include <iostream>


#include <thread>


void print(std::string message)

{

    std::cout << message << "\n";

}


int main()

{

    std::string message = "Hello, C++11 threads!";

    std::thread t(&print, message);

    t.join();

    return 0; 

} 

(http://stackoverflow.com/questions/13128461/getting-error-when-using-pthread-create)

저작자표시 비영리 (새창열림)

'소프트웨어' 카테고리의 다른 글

[c++] 변수 선언에 대해서  (0) 2014.01.29
[c++] const char vs char 비교 실험  (0) 2014.01.28
[ubuntu] terminal 다중 창 'Terminator' ( multi terminal )  (0) 2014.01.23
[javascript] chapter6. Objects _발번역  (0) 2014.01.22
[c++] ifndef / endif  (0) 2014.01.22
    '소프트웨어' 카테고리의 다른 글
    • [c++] 변수 선언에 대해서
    • [c++] const char vs char 비교 실험
    • [ubuntu] terminal 다중 창 'Terminator' ( multi terminal )
    • [javascript] chapter6. Objects _발번역
    개발자_이훈규
    개발자_이훈규
    혼자 꽁양꽁양 개발하면서 놀아요~ - 노트같은 블로그

    티스토리툴바