[C++] Wątki
Ostatnio zmodyfikowano 2018-02-09 10:32
kubasuperpl Temat założony przez niniejszego użytkownika |
[C++] Wątki » 2018-02-07 19:37:58 Witam. Otóż mam problem z wątkami w C++ (thread). Kiedy chcę uruchomić przykładowy kod to podczas kompilacji dostaję błędy: multithread.cpp: In function 'int main()': multithread.cpp:10:2: error: 'thread' was not declared in this scope thread t(func1); ^~~~~~ Kompiluję z argumentami -lpthread i -std=c++11 Kod źródłowy: #include <iostream> #include <thread> using namespace std; void func1() { cout << "ABC" << endl; } int main() { thread t( func1 ); return 0; }
Moje oprogramowanie: Windows 7 Professional Code::Blocks 17.12 MinGW 6.3.0 |
|
geceves |
» 2018-02-07 23:46:20 Czy to jedyny błąd? Pojawia się może error: thread: No such file or directory
? |
|
kubasuperpl Temat założony przez niniejszego użytkownika |
» 2018-02-08 17:28:24 Nie jest tylko ten jeden. |
|
geceves |
» 2018-02-08 23:26:48 No to będziesz musiał zmienić kompilator. Why MinGW has no threading classes
It seems that for cross-platform threading implementation, the GCC standard library relies on the gthreads/pthreads library. If this library is not available, as is the case with MinGW, the std::thread, std::mutex, std::condition_variable are not defined. However, higher-level mutex helper classes are still defined in <mutex> and are usable. Hence, this implementation does not re-define them, and to use these helpers, you should include <mutex> as well, as explained in the usage section.
|
albo to pobrać i potestować: https://github.com/meganz/mingw-std-threads |
|
mateczek |
» 2018-02-09 09:07:02 ja obecnie na Windowsie korzystam z Mingw zainstalowanego za pomocą msys2 i mi ten kod się kompiluje. Nie mam domyślnej instancji codeblocksa by sprawdzić. Ale z tego co widzę auto wątku również nie jedzie na domyślnym kompilatorze tylko na ręcznie dodanym. Również nie zdarzyło mi się bym miał problem z wątkami (tyle że pisałem w Qt::thread nie std::thread)I na domyślnych konfiguracjach qt-creatora ze zintegrowanym mingw działały zawsze.
|
|
kubasuperpl Temat założony przez niniejszego użytkownika |
» 2018-02-09 10:14:14 Na razie spróbuję użyć mingw-std-threads. Próbowałem też użyć wątków z SFML (sf::Thread) ale nie działały tak jak bym chciał. |
|
j23 |
» 2018-02-09 10:15:47 Niech OP zainstaluje albo MinGW + MSYS2 (najlepiej), albo MinGW-w64 (przy instalacji wybrać posixowy threading model). |
|
kubasuperpl Temat założony przez niniejszego użytkownika |
» 2018-02-09 10:32:33 Ok już działa, zamykam temat. |
|
« 1 » |