小编hud*_*dac的帖子

VMware 工作站 16 上的 Ubuntu 22.04 虚拟机冻结

每个程序员都需要有一台开发机器来启动。其中之一是为其他人准备VM。例如,我们需要在每个 ubuntu 新版本中为所有团队成员安装 Odoo ERP。

Ubuntu 22.04我有一个以上的临时安装VMware workstation 16。

我的主人是Windows 10.

使用虚拟机一段时间后,每次使用几分钟后就开始冻结。
在某些情况下,在虚拟机冻结之前,我注意到我的一些应用程序的 CPU 利用率达到 100%,而这种情况永远不会发生。当尝试使用perfVM 调试它时,它再次冻结,因此我无法理解为什么我的应用程序达到 100%。

为什么我的虚拟机冻结?

ubuntu virtual-machine

4
推荐指数
1
解决办法
9624
查看次数

我可以继承运营商>>吗?

我有以下问题:让我们说类Item保存产品的序列号,类Book是Item继承类Item的序列号.我必须operator>>为每个班级创造和使用.我想创建operator>>到Item,然后只是istream在本书的实现中调用它,但我不知道如何.

代码如下:

class Item
{
protected:
    int _sn;
public:
    Item();
    ~Item();
    ...
    const istream& operator>>(const istream& in,const Item& x)
        {
        int temp;
        in>>temp;
        x._sn=temp;
        return in;
        }
};

class Book
{
private:
    char _book_name[20];
public:
    Book();
    ~Book();
    ...
    const istream& operator>>(const istream& in,const Book& x)
        {
        char temp[20];
        ////**here i want to use the operator>> of Item**////
        in>>temp;
        strcpy(x._book_name,temp);
        return in;
        }
};

int …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
145
查看次数

是否可以在函数中使用va_list方法两次?

我想在一个函数中使用va_list方法两次.我能这样做吗?

#include <cstdarg>

void printFDS(int num_fds, ... , const char *fmt, ...) {

    va_list fds, args;
    va_start(fds, num_fds);
    va_start(args, fmt);

    for (int i = 0; i < num_fds; i++) {
        vsprintf(va_arg(fds, FILE*), fmt, args);
    }
    va_end(args);
    va_end(fds);
}
Run Code Online (Sandbox Code Playgroud)

所以我将能够像这样调用该函数:

printFDS(1, stderr, "Error: %s\n", stderror(errno));
Run Code Online (Sandbox Code Playgroud)

要么 printFDS(2, stderr, otherFD, "Error: %s\n", stderror(errno));

而 FILE *otherFD = fopen ("somefile", "w");

我的目的:在fd的列表上打印信息..

谢谢

c++ formatting

2
推荐指数
1
解决办法
756
查看次数

bash通配符,if语句中带有变量

我想根据此解决方案在字符串中找到子字符串。

但是由于某种原因,它不适用于变量:

str="abcd";
substr="abc";
if [[ "${substr}"* == ${str} ]]
then
        echo "CONTAINS!";
fi
Run Code Online (Sandbox Code Playgroud)

string bash if-statement wildcard

2
推荐指数
1
解决办法
3084
查看次数

错误:预期')'之前';' 代币

我有这个愚蠢的小问题,我无法解决......

exer3.c: In function ‘shm_pipe_pipe’:
exer3.c:69:39: error: expected ‘)’ before ‘;’ token
exer3.c:69:39: error: too few arguments to function ‘shmget’
/usr/include/i386-linux-gnu/sys/shm.h:54:12: note: declared here
Run Code Online (Sandbox Code Playgroud)

line的69周围环境:

pipes_array[i].m_key = 1;
key = i;

pipes_array[i].m_shmid = shmget(key, PIPE_SIZE, IPC_CREAT | IPC_EXCL | 0600); //69

if (pipes_array[i].m_shmid < 0) {
    perror("Error");
    return -1;
}
Run Code Online (Sandbox Code Playgroud)

然后:

exer3.c: In function ‘shm_pipe_read’:
exer3.c:111:60: error: expected ‘)’ before ‘;’ token
Run Code Online (Sandbox Code Playgroud)

line的111环境:

    current_bytes_to_read = total_bytes_to_read <= pipes_array[i].m_bytes_in_pipe ? total_bytes_to_read : pipes_array[i].m_bytes_in_pipe;

    //reading the information
    if ((pipes_array[i].m_roffset + current_bytes_to_read) < …
Run Code Online (Sandbox Code Playgroud)

c

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

pthread_self()贵吗?

是pthread_self()昂贵ubuntu 12.04?
它是否使用系统调用?

我想在pthread_self()每次线程写入日志时调用,所以我会知道哪个线程写入日志并在日志中提及它.所有线程都写入同一个日志文件.

c c++ performance multithreading ubuntu-12.04

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

java中的并发读/写缓冲区byte []

我是Java的新手,我想实现byte[]一个线程可以写入的缓冲区,另一个线程可以读取.
它听起来应该已经实现了java,但我花了几个小时试图找到/理解几个类,我不明白它是否做我想要的,以及如何使用它.
我看到BufferedInputStream,ByteBuffer,ByteChannel,BlockingQueue...

有人可以指出一个更具体的方向吗?我用SDK 1.6

java multithreading buffer byte

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

一个读者一个编写者,int或atomic_int

我知道这不是一个新问题,但在阅读了关于c ++ 11内存栅栏后我感到困惑;

如果我有一个读者线程和一个编写器线程.
我可以使用普通的int吗?

    int x = 0; // global
writer    reader
x = 1;    printf("%d\n", x);
Run Code Online (Sandbox Code Playgroud)

这种行为是不确定的?
我可以在读者线程中获得未定义的值吗?
或者就像使用std::atomic_uint_fast32_t或std::atomic<int>?因此,价值将会到达读者线程 - 最终.

    std::atomic<int x = 0; // global
writer                                    reader
x.store(1, std::memory_order_relaxed);    printf("%d\n", x.load(std::memory_order_relaxed));
Run Code Online (Sandbox Code Playgroud)

答案取决于我使用的平台吗?(例如x86),所以加载/存储普通int是一条CPU指令?

如果两种行为都相似,那么我是否应该期望两种类型的性能相同?

c++ multithreading atomic memory-fences c++11

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

是否可以#Include一个"钻石继承"结构?

我正在尝试用C做一些项目.

我想知道是否有可能#include从同一个文件制作两次,以回忆钻石遗产的方式.

即

  • 在ac有#include "a.h"
  • 在公元前有#include "b.h"
  • 在bh有#include "a.h"

是否有可能#include "b.h"在交流?

我收到一个错误:

some_variable already defined in a.obj
Run Code Online (Sandbox Code Playgroud)

c include

0
推荐指数
1
解决办法
367
查看次数

使用特定参数键入特定构造函数的声明

我有这个结构:

struct A {
    A(int a, bool b):a(a), b(b) {};
    int a;
    bool b;
}
Run Code Online (Sandbox Code Playgroud)

我可以以某种方式声明具有特定参数的特定构造函数调用的类型声明吗?

我的意思是,像这样:

typedef A(2, false) A_2_false;
Run Code Online (Sandbox Code Playgroud)

所以我可以使用如下:

const A a_func() { return A_2_false; };
Run Code Online (Sandbox Code Playgroud)
  • 它会提醒std::bind您调用函数的位置,并且可以预先设置一些变量而不是std::place_holders.

  • 我试过用std::integral_constant但没有运气.

  • 我不想用 #define

谢谢

---更新---

我想要实现的目标:

我正在编写一个回调函数:
typedef std::function<const A()> CbFunc
一个简单的用户应该使用CbFunc和返回const A.我想让事情更简化,所以用户回调函数可以是:

const A userCbFunc() {
    ...
    ...
    // Good thing happend
    return A_2_false;
    ...
    ...
    // Bad thing happend
    return A(99, true);
}
Run Code Online (Sandbox Code Playgroud)

我想让Good thing happened返回类型更简化,所以它将 …

c++ c++11

0
推荐指数
1
解决办法
84
查看次数