问题列表 - 第318066页

可以使用每任务虚拟线程 ExecutorService 来执行 PlatformThread 吗?

我知道应该使用 a 来用新的虚拟线程包装所有任务VirtualThread,而不是使用 pooling s,因为这并不能真正带来好处。Executors.newVirtualThreadPerTaskExecutor()

我想知道是否应该阻止PlatformThread使用这样的执行者执行 a ,并且通常Threads 是否完全不应该传递给执行者。

try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
  Runnable platformThread = Thread.ofPlatform().unstarted(someTask);
  executor.execute(platformThread);
}
Run Code Online (Sandbox Code Playgroud)

ThreadFactory由于执行器的原因,以这种方式创建的平台线程将被虚拟线程包装。我试图了解这是否有意义,或者通常Thread对象是否不应该传递给ExecutorServices.

java multithreading virtual-threads java-21

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

如何使用list_rbind在列表中保留命名但0行的小标题?

假设我有一个包含命名元素的列表。元素是小标题。\n我想将列表转换为一个小标题。

\n

purrr 的list_rbind工作原理,但有一个严重的缺点(至少对于我的目的而言),它会删除 0 行 tibble 元素(尽管它是一个命名元素)。

\n
library(tidyverse)\n\nli <- list("a"=tibble(x=1), "b"=tibble(x=2), "c"=tibble(x=NULL))\nli\n#> $a\n#> # A tibble: 1 \xc3\x97 1\n#>       x\n#>   <dbl>\n#> 1     1\n#> \n#> $b\n#> # A tibble: 1 \xc3\x97 1\n#>       x\n#>   <dbl>\n#> 1     2\n#> \n#> $c\n#> # A tibble: 0 \xc3\x97 0\n\n\nli %>% purrr::list_rbind(., names_to="element_names")\n\n#> # A tibble: 2 \xc3\x97 2\n#>   element_names     x\n#>   <chr>         <dbl>\n#> 1 a                 1\n#> 2 b                 2\n
Run Code Online (Sandbox Code Playgroud)\n

我正在寻找的结果是

\n
#>   element_names     x\n#>   <chr>         <dbl>\n#> 1 a                 1\n#> 2 b                 2\n#> …
Run Code Online (Sandbox Code Playgroud)

r purrr

4
推荐指数
2
解决办法
136
查看次数

RAD Studio 平台选择问题

安装 Delphi 11 CE 后,正如我在视频中看到的那样,应该会出现一个窗口来下载不同的平台。

相反,我有一条错误消息:

图像

我试图寻找问题所在。我将源更改为sourceURL = https://getit.embarcadero.com. 之后,我有一个不同的信息:

图像

当我尝试打开一个项目时,它说:

无法加载该项目,因为所需的个性 Delphi.Personality 不可用。

如果我打开 GetIt 包管理器,它不会显示任何内容,只是没有结果,就像我无法从中下载任何内容一样。

请帮我解决这个问题。

顺便说一下,我使用的是 Windows 11。我在VirtualBox中的Win 10上尝试过,结果是一样的。

我也尝试过使用 Wifi 和以太网。

我重新启动系统,并重新安装Delphi,但问题仍然存在。

windows delphi installation rad delphi-11-alexandria

5
推荐指数
0
解决办法
1186
查看次数

文件权限为0666,但root也打不开

我正在尝试flock:

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(){
    mode_t m = umask(0);
    int fd = open("/tmp/test.lock", O_RDWR | O_CREAT, 0666);
    if(fd == -1){
        printf("open failed. errno: %d, %s\n", errno, strerror(errno));
    }
    umask(m);
    int res = flock(fd, LOCK_EX);
    if(res != 0){
        printf("flock failed. errno: %d, %s\n", errno, strerror(errno));
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我使用 运行可执行文件sudo,那么通常不会出现错误。但是,如果我以普通用户身份运行,我会得到以下sudo过程open failed. errno: 13, Permission denied::

#include <sys/types.h>
#include <sys/stat.h>
#include …
Run Code Online (Sandbox Code Playgroud)

c linux sudo file-permissions

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

如何编写接受类型和整数的可变参数列表的模板

我正在尝试编写一个接受可变参数“对列表”的模板。“对”将是一种类型,然后是一种尺寸。

我写了一些有效的东西:

#include <cstddef>
#include <iostream>

template <typename T, size_t N>
class DeferPair
{
    using Type = T;
    static constexpr size_t kSize = N;

public:
    void defer(const T& e)
    {
        std::cout << __PRETTY_FUNCTION__ << std::endl;
        //Defer this specific type into a fixed-length/statically-allocated queue
        //Discard oldest if the queue is already full
    }
};

template <typename... Pairs>
class Defer;

template <typename Pair, typename... RemainingPairs>
class Defer<Pair, RemainingPairs...> : public Pair, public Defer<RemainingPairs...>
{
public:
    using Pair::defer;
    using Defer<RemainingPairs...>::defer;
};

template <typename …
Run Code Online (Sandbox Code Playgroud)

c++ templates

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

为什么for循环没有结束?

我编写了一个程序,将变量定义np为int并使用 对其进行初始化getchar。但这样程序就不会退出for循环。如果我使用scanf它运行良好。为什么会发生这种情况?

#include <stdio.h>
#include <stdlib.h>

typedef struct parents {
    char fathername[30];
    char Mothername[50];
} parents;

struct person {
    char firstname[30];
    char Lastname[30];
    int age;
    parents p;
};

int main() {
    int np;
    printf("The number of people: ");
    np = getchar(); //scanf("%d", &np);

    struct person *point = malloc(np * sizeof(struct person));

    int i = 0;
   
    for (i = 0; i < np; i++) {
        printf("Give your name: ");
        scanf("%s", &point[i].firstname); …
Run Code Online (Sandbox Code Playgroud)

c

3
推荐指数
2
解决办法
213
查看次数

图上特定点的 Fireworks 动画

如何让烟花动画在线图动画上的特定点上播放,如下所示:

\n

我有这个动画可以产生烟花的效果。

\n
library(tidyverse)\nlibrary(sf)\nlibrary(gganimate)\nlibrary(magick)\n\n#Explosion\xe2\x80\xa8\nfor (z in 1:3) { \np1 <- map_dfr(1:10, ~crossing(x = runif(30),\nnesting(\ny = seq(1, .x, length.out = 10)^0.5,\nt = 1:10))\n)%>%\nggplot(aes(x, y=y+z)) +\ngeom_point(color = \'red\') +\ncoord_polar() +\ntransition_time(t) +\nshadow_wake(0.5) \n}\np2_gif <- animate(p1, renderer = gifski_renderer(), nframes = 70, fps = 50, width = 250, height = 250)\nanim_save("~/Downloads/EV2.gif")\n
Run Code Online (Sandbox Code Playgroud)\n

我怎样才能让烟花动画在这个 GGanimate 情节的最高点播放:

\n
library(ggplot2)\nlibrary(gganimate)\nlibrary(ggthemes)\nlibrary(forcats)\nlibrary(scales)\nlibrary(transfrmr)\nlibrary(dplyr)\nlibrary(ggbreak) \nlibrary(patchwork)\nlibrary(magick)\n\n\ndon <- readr::read_csv("~/Downloads/anim_test5.csv")\n\nMonths= as.Date(don$Date, format = "%d-%b-%y")\n\n\n\na2<- don %>%\n  ggplot(aes(x=Months)) +\n    geom_point(aes(y = Cumulative), color="#C91D42",  alpha=0.4) +\n    geom_line(aes(y = Cumulative), color="#C91D42",  alpha=0.4) +\n    theme_economist() +\n    scale_colour_economist() …
Run Code Online (Sandbox Code Playgroud)

r

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

如何确定自定义TComponent所在的DFM路径?

在自定义中,我需要获取使用 的或文件TComponent的路径。显然,这仅在设计时需要。*.dfm*.pasTComponent

语境

与上一个问题类似:
How to detector the dfm/project path from a custom control while in the Designer?

我创建了一个类似于 TImageCollection 的自定义 TControl,但具有所有应用程序的共享图像数据库。为此,控件读取一个项目元文件,该文件是一个 XML,其中包含要包含在图像集合中的图像列表。在设计器中,图像是直接从图像文件中读取的,但在运行时,图像位于编译期间生成的资源(*.res)文件中。

if csDesigning in Self.ComponentState then
  loadImagesFromFiles(...)
else
  loadImagesFromResource(...)
Run Code Online (Sandbox Code Playgroud)

在以前的版本中(对于上面链接的其他问题),我尝试获取项目的路径,虽然这似乎不可能,但我找到了一种获取活动项目路径的方法。然而,当 IDE 打开多个项目时,这就很成问题了。

我决定改用另一种方法,即使用相对于使用组件的 DFM 的路径。这个应该比较靠谱。

TComponent不幸的是,对于放置在 DFM 上的自定义程序来说,了解 DFM 的位置似乎并不容易。

解决方案(一半)

我尝试了几种解决方案IOTA,但还没有任何效果。

此处提供的方法将路径返回到自身TComponent,而不是返回到使用它的 DFM。

我设法遵循相同的策略迭代模块,但找到哪个模块包含给定的模块TComponent并不简单:

function GetCurrentDfmPath(AComponent: TComponent): String;
var
  ModuleServices: IOTAModuleServices;
  Module: IOTAModule;
  idx: integer;
begin
  Result := '';
  SourceEditor := nil;

  if SysUtils.Supports(BorlandIDEServices, …
Run Code Online (Sandbox Code Playgroud)

delphi designer tcustomcontrol

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

将expo更新到50.0后如何修复react-native错误

当我npm run ios在终端中运行时,出现以下错误

错误:node_modules/expo-router/entry.js:[BABEL]:expo-router/babel 已弃用,取而代之的是 SDK 50 中的 babel-preset-expo

我尝试安装 babel-preset-expo,但它已经安装了

ios reactjs react-native npm-run expo

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

Stroustrup 书中关于对象切片的示例中的混乱

在《C++ 编程语言》第 17.5.1.4 节中,有以下示例:

\n
struct Base {\n  int b;\n  Base(const Base&);\n};\n\nstruct Derived {\n  int d;\n  Derived(const Derived&);\n};\n\nvoid naive(Base* p) {\n  B b2 = *p;\n};\n\nvoid user() {\n  Derived d;\n  naive(&d);\n  Base bb = d;\n};\n
Run Code Online (Sandbox Code Playgroud)\n

I\xe2\x80\x99 省略了代码中的注释,并在naive() (应该是Base b2 ?) 中包含了明显的拼写错误。

\n

我\xe2\x80\x99m 只是混淆了问题到底是什么:我没有理由期待一个Derived 在任何一种情况下都会复制 a 。我觉得好像我应该在这里遗漏一些东西,但我只是无法理解这个 \xe2\x80\x9cexample\xe2\x80\x9d 的意义。

\n

谁能解释一下吗?如果这确实是一个富有洞察力的例子,我\xe2\x80\x99d不想对此一无所知。在此输入图像描述

\n

c++ object-slicing

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