RDK Documentation (Open Sourced RDK Components)
crashingthread.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #include "crashingthread.h"
20 #include <QDebug>
21 #include <math.h>
22 
23 CrashingThread::CrashingThread(QObject *parent)
24  : QThread(parent),
25  th_num(-1)
26 {
27 }
28 
29 void CrashingThread::run()
30 {
31  qDebug() << "Thread " << getThreadNumber()
32  << " with pid: " << thread()->currentThreadId()
33  << " starting\n";
34 
35  //some work
36  double result = 0.0;
37  for (int i = 0; i < 1000; ++i)
38  {
39  result = result + sin(i) * tan(i);
40  }
41 
42  qDebug() << "Thread " << getThreadNumber() << " about to rise SIGSEGV\n";
43  volatile int* x = (int*)42;
44  *x = 1;
45 }
46 
47 int CrashingThread::getThreadNumber() const
48 {
49  return th_num;
50 }
51 
52 void CrashingThread::setThreadNumber(int num)
53 {
54  th_num = num;
55 }