Fehler #666 » main.hpp
| 1 |
#if ! defined( main_hpp )
|
|---|---|
| 2 |
#define main_hpp
|
| 3 |
#include <stdio.h>
|
| 4 |
|
| 5 |
#include <QString>
|
| 6 |
#include <QRegularExpression>
|
| 7 |
#include <QRegularExpressionMatch>
|
| 8 |
#include <QFile>
|
| 9 |
#include <QTimer>
|
| 10 |
#include <QThread>
|
| 11 |
#include <QTextStream>
|
| 12 |
#include <QCoreApplication>
|
| 13 |
#include <stdio.h>
|
| 14 |
#include <iostream>
|
| 15 |
|
| 16 |
//#define T std::atomic<int>
|
| 17 |
#define T int
|
| 18 |
|
| 19 |
extern bool b1; |
| 20 |
extern bool b2; |
| 21 |
extern bool b3; |
| 22 |
extern bool b4; |
| 23 |
|
| 24 |
class CCounters: public QThread |
| 25 |
{
|
| 26 |
Q_OBJECT
|
| 27 |
|
| 28 |
int counter1=10000000; |
| 29 |
bool& m_pFinished; |
| 30 |
|
| 31 |
public:
|
| 32 |
static T gcounter; |
| 33 |
CCounters( bool& finished ) |
| 34 |
:m_pFinished(finished) |
| 35 |
{
|
| 36 |
}
|
| 37 |
void run() override |
| 38 |
{
|
| 39 |
while( counter1 ) |
| 40 |
{
|
| 41 |
counter1--; |
| 42 |
/*
|
| 43 |
int i1=gcounter;
|
| 44 |
i1++;
|
| 45 |
gcounter=i1;
|
| 46 |
*/
|
| 47 |
//gcounter++;
|
| 48 |
__atomic_add_fetch (&gcounter, 1, __ATOMIC_SEQ_CST); |
| 49 |
// __ATOMIC_ACQ_REL);
|
| 50 |
|
| 51 |
}
|
| 52 |
m_pFinished=true; |
| 53 |
if( b1 && b2 && b3 && b4 ) |
| 54 |
{
|
| 55 |
// printf("Finished: %d\n", gcounter );
|
| 56 |
std::cout << "Atomic value: " << gcounter << std::endl; |
| 57 |
QCoreApplication::exit(0); |
| 58 |
}
|
| 59 |
}
|
| 60 |
};
|
| 61 |
|
| 62 |
|
| 63 |
#endif // ? ! main_hpp
|