小编Art*_*ner的帖子

在Ada中中止使用重新排列的受保护对象的进程

我的程序遇到了一些麻烦.

我有一个进程调用一个函数(Take_Job),它应该保持阻塞状态,直到一个时间(MINIMUM_WAIT)通过.如果不是这样,将出现通知这种情况的消息.

for Printer_Id in Type_Printer_Id loop
   select
      delay MINIMUM_WAIT
      Pragma_Assert (True, "");
   then abort
      Take_Job (Controller,
                     Printer_Id,
                     Max_Tonner,
                     Job,
                     Change_Tonner);
      Pragma_Assert
        (False,
           "Testing of Take_Job hasn't been successful. It should have remained blocked.");
   end select;
end loop;
Run Code Online (Sandbox Code Playgroud)

函数Take_Job调用受保护对象中的条目:

procedure Take_Job (R                 : in out Controller_Type;
                         Printer      : in     Type_Printer_Id;
                         Siz          : in     Typo_Volume;
                         Job          :    out Typo_Job;
                         Excep_Tonner :    out Boolean) is
begin
   R.Take_Job(Printer, Siz, Job, Excep_Tonner);
end Take_Job;
Run Code Online (Sandbox Code Playgroud)

其中"R"是受保护对象.

以下代码是受保护对象的条目.实际上,"when"条件为True,因为我需要使用条目的参数检查一些内容.由于Ada不允许我这样做,我复制受保护对象内的参数并调用"延迟条目",然后在"延迟条目"中,我将确保在继续之前满足条件.

entry Take_Job(Printer_Id: in Type_Printer_Id; Remaining: in Type_Volume; Job: …
Run Code Online (Sandbox Code Playgroud)

concurrency ada task protected-resource

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

为什么malloc在这里引起内存损坏?

我不断收到以下错误:

*** Error in `./vice': malloc(): memory corruption: 0x08e77530 ***
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

相关代码为:

open_result *
open_file_1_svc(open_args *argp, struct svc_req *rqstp)
{
    static open_result  result;
    int obtained_fd;
    int just_read;
    int total_read = 0;
    int max_bytes_read = 1024;
    char *ptr_file;
    char *pathName = "MyFiles/"; // strlen = 8
    int toReserve;

    xdr_free((xdrproc_t)xdr_open_result, (char *)&result);

    // Construct full name of the file (in "MyFiles")
    toReserve = strlen(argp->fname) + strlen(pathName) + 1; // "\0"
    char *fullName = malloc(toReserve*sizeof(char));
    fullName = strdup(pathName);
    fullName = strcat(fullName, …
Run Code Online (Sandbox Code Playgroud)

c malloc rpc memory-management memory-corruption

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