- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
I have the following issues that can be represented by both those 2 links:
http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c
http://stackoverflow.com/questions/6485705/why-does-this-simple-stdthread-example-not-work
the problem is that I am getting std::exception on shutdown and negative return code..
the question is does the -pthread flag work with icpc? (seems like it doesn't)
how should I make this work?
Thanks,
Alon
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi alon,
Why -lpthread does not work with icpc? It works.
I do not have issues to build the code in the first link, please post your code and compiler version/options used.
$ cat temp.cpp #include <string> #include <iostream> #include <thread> using namespace std; //The function we want to make the thread run. void task1(string msg) { cout << "task1 says: " << msg; } int main() { // Constructs the new thread and runs it. Does not block execution. thread t1(task1, "Hello"); //Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution. t1.join(); } $ icc temp.cpp -std=c++11 -lpthread $ ./a.out task1 says: Hello$
Thanks,
Shenghong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
not lpthread, -pthread for compiler flags, the q is what is the return code, not if it works(it does work)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
icc 15.0 supports the -pthread option. The links you provided contain various code examples. If you still have a problem with icc 15.0, kindly post YOUR example and we'll investigate further.
Patrick
[U536960]$ cat U536960.cpp
#include <string>
#include <iostream>
#include <thread>
using namespace std;
//The function we want to make the thread run.
void task1(string msg)
{
cout << "task1 says: " << msg;
}
int main()
{
// Constructs the new thread and runs it. Does not block execution.
thread t1(task1, "Hello \n");
t1.join();
return 0;
}
[U536960]$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.133 Build 20141023
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
[U536960]$ icc -std=c++11 U536960.cpp -pthread && ./a.out
task1 says: Hello
[U536960]$

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page