非常に単純なクロスプラットフォーム(linux / windows)スレッド関数を作成する方法を知っています。これは私のサンプルコードです:
#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
これは最初は奇妙な質問のように見えるのではないかと思いますが、私は初心者であり、C++を理解する必要があることを忘れないでください。「わからない」というコメントを残した部分は、お気軽に編集してください。
これが間違った質問だと思われる場合は、私がどのように質問すべきかについてコメントを残してください。