매우 간단한 크로스 플랫폼 (Linux/Windows) 스레드 기능을 만드는 방법을 알고 있습니다.다중 플랫폼 목적을위한 Clone C++ 데이터 유형
#if LINUX
#include <pthread.h>
ThreadHandle createThread(???* callback, void* data) { //I dont know what is data type of function pointer, sorry
pthread_t handle;
pthread_create(&handle, 0, callback, (void*)data);
return (ThreadHandle)handle;
}
define_data_type ThreadHandle = pthread_t; //I don't know how this is done at all, sorry
#endif
#if WINDOWS
#include <windows.h>
ThreadHandle createThread(???* callback, void* data) {
HANDLE handle = CreateThread(
NULL, // default security attributes
0, // use default stack size
callback, // thread function name
data, // argument to thread function
0, // use default creation flags
NULL); // returns the thread identifier - I don't need this, do I?
}
define_data_type ThreadHandle = HANDLE; //I don't know how this is done at all, sorry
#endif
나는이 처음 veird 질문처럼 보이지만, 나는 초보자있어 마음에 계속됩니다 두려워, 나는 C를 이해할 필요 ++ : 이것은 내 샘플 코드입니다. 언제든지 에을 입력하십시오. "모르겠다"는 부분이입니다.
이것이 잘못된 질문이라고 생각되면 어떻게해야하는지에 대한 의견을 남겨주세요. 모든 스레드 기능
모든 환경에서 ['std :: thread'] (http://en.cppreference.com/w/cpp/thread)가 작동합니까? –
와우, 그 std :: 모든 치료법처럼 보입니다. 매번 다중 플랫폼을 찾으면 누군가 std :: function으로 나타납니다. 고맙습니다. 그러나 나는 아직도이 크로스 플랫폼 물건을하는 방법에 관심이 있어요. –
궁금하거나 환경이 아직 C++ 11이 아닌 경우 Boost에서 많은 다른 OS로 포팅 된 쓰레드 래퍼 클래스를 볼 수있다. –