小编jus*_*uff的帖子

在某些条件下非常奇怪的代码,包括优化

我有这段代码:

#include <stdio.h>     

void optimization_headache()    
{    
    int t = 11;    
    int l[1047] = {0};    
    int u_lu[23] = {0};    

    int u = 0;    

    l[0] = 0;    
    l[1] = 0;    

    do {    
        u++;    
        //printf("Incrementing u, now u is %d\n", u);     
        u_lu[u + 1] = u - l[u + 1];    
    } while ((u < t * 2) && (l[u + 1] <= t));    

    printf("u = %d, l[u] = %d, t = %d, u_lu[u] = %d\n", u, l[u], t, u_lu[u]);    
}    

int main()    
{ …
Run Code Online (Sandbox Code Playgroud)

c c++ optimization gcc

8
推荐指数
1
解决办法
168
查看次数

使用互斥锁时尝试引用已删除的功能

我在项目上遇到了一个奇怪的错误.我创建了一个超级简单的例子来重新创建错误.

我创造了一个班级.我想在这堂课中做的是为我的班级设置一种"getter"功能,填充a的值struct.在主应用程序中,用户将实例化它struct,将其传递给成员函数,并能够struct在返回时读取值.由于实际类的设计,这必须在一个单独的线程中发生.这就是我所拥有的:

myClass.h:

#ifndef __MY_CLASS_H__
#define __MY_CLASS_H__

#include <mutex>

class myClass {
public:
    struct my_struct_s {
        int field1;
        short field2;
    };

    int get_data(my_struct_s & my_struct);

private:

};

#endif /* __MY_CLASS_H__ */
Run Code Online (Sandbox Code Playgroud)

myClass.cpp:

#include "myClass.h"

int myClass::get_data(struct my_struct_s & my_struct)
{
    int var1 = 5;
    char var2 = 2;

    my_struct.field1 = var1;
    my_struct.field2 = var2;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Main.cpp的:

#include "myClass.h"
#include <iostream>
#include <thread>
#include <Windows.h>

bool thread_running;
std::thread thread;

void run_thread(myClass & lmyClass) …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading struct c++11

5
推荐指数
1
解决办法
9612
查看次数

标签 统计

c++ ×2

c ×1

c++11 ×1

gcc ×1

multithreading ×1

optimization ×1

struct ×1