threads

Hi,

i have a simple program, that shall use multithreading ... smth like (modified for simplicity ...maybe syntax errors)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <thread>
#include <chrono>
#define MAX_BUF 1024

void outRead(){
/*   */
int num       = 0;
int readcount = 0;
// well do smth. ... and wait
while(num == 0 && count < 100){
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
        num++;
        readcount = readcount + num;
}
printf("Received\n");
}
int main()
{
    /* open, read, and display the message from the FIFO */

    printf("So far ... \n");
    std::thread readThread(outRead);
    readThread.join();

    return 0;
}



It won't be executed properly and i get an error:

std::system_error what() Operation not permitted


I think it has to deal with my Compiler and my IDE ... but i am not too sure about all that. I use CodeBlocks and gcc ... and i have added additional opts so that it compiles ...

Anyway, does anyone have a hint what to look for ?
Or should one just use another lib, like boost or such things ?

Best regards and thanks for reading,
...

Last edited on
What is count on line 10 ?

codeblocks default compiler doesn't support std::thread. you need gcc 4.9 or higher. open a command prompt and type gcc --version it should say 4.9 or higher.
Last edited on
Hi,

well, i read before that i'd need to add some compiler options, which is possible using code blocks, but i'm not sure about the version of gcc.
Anyway, i was sure that this could not be my issue, because i haven't encountered any problems compiling the application ... count is readcount ... just a mistake of mine ... as i said, i simplified by removing some things. .... tic toc ....
......
I checked my version and it said 4.6.3 ... 4.9 is not in my synaptic menu. I'll have a look for it elsewhere.

Thanks so far,
...
> I checked my version and it said 4.6.3 ... 4.9 is not in my synaptic menu. I'll have a look for it elsewhere.

CodeBlocks + GCC 5.1 + C++11 threads:
http://www.cplusplus.com/forum/beginner/169434/#msg847452
Well,

just for me to understand ... why does my program compile (gcc 4.6.3 ... ) using <threads.h> when this is not supported ?
My error is a runtime error ... and that is what i don't understand. What i found on the net was all dealing with compiler version and support for "thread" ... but (although, i'm the beginner here) should result in a compiler error, or not ?

By the way, i just started a first effort to install gcc 5.2 but it doesn't work. I have some problems running configure and it seems i have to install a lot of things before ... that's what my logfile tells me ...

Maybe i should as well upgrade my whole system ... and then see if gcc 5.2 is on my synaptic list.

Best regards so far and thanks for the help until now,
...
Last edited on
Hi again,

... well probably i have to ... i'll try that. But anyway, i won't sleep well until i have a reason why that messy thing is throwing that exception ...
Maybe linking pthreads makes it work, but why ?

Anyway, thanks. I'll be back when i treid all that.
Best regards,
...
Topic archived. No new replies allowed.