Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在多线程中使用stxxl_C++_Stxxl - Fatal编程技术网

C++ 在多线程中使用stxxl

C++ 在多线程中使用stxxl,c++,stxxl,C++,Stxxl,下面的程序,与一起崩溃 libc++abi.dylib: terminating with uncaught exception of type stxxl::io_error: Error in virtual void stxxl::ufs_file_base::lock() : fcntl(,F_SETLK,) path=/var/tmp/stxxl fd=5 : Resource temporarily unavailable: unspecified iostream_category

下面的程序,与一起崩溃

libc++abi.dylib: terminating with uncaught exception of type stxxl::io_error: Error in virtual void stxxl::ufs_file_base::lock() : fcntl(,F_SETLK,) path=/var/tmp/stxxl fd=5 : Resource temporarily unavailable: unspecified iostream_category error
Abort trap: 6
这看起来很像我的两个线程试图使用相同的文件处理程序/file来更新stxxl文件til/var/tmp

在stxxl中有使用多个文件的多线程的技巧吗

#include <stxxl/queue>
#include <iostream>

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>




void test() {
  typedef stxxl::queue<unsigned int> queue;
  queue my_queue;
  for(unsigned long long i = 0; i != 1024L * 1024 * 1024; i++)
    my_queue.push(10);

  std::cout << "queue_size " << my_queue.size() << std::endl; 

  while(my_queue.size() != 0)
    my_queue.pop();

  std::cout << "queue_size " << my_queue.size() << std::endl; 
}

int main()
{
  pid_t pid;
  pid_t cpid;
  int status;


  pid = fork();

  if (pid == 0) 
    {
      test();
      exit(0);
    } else 
    {

      test();
      if ((cpid=wait(&status)) == pid){
        std::cout << "Child " << pid << " returned" << std::endl;
      }
    }

    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
无效测试(){
typedef stxxl::队列;
排队等候;
for(无符号长i=0;i!=1024L*1024*1024;i++)
我的队列。推送(10);

std::cout在STXXL 1.4.0中,您还可以在.STXXL配置文件中使用“####”。打开文件时,将用当前pid替换“####”


请注意,在调用第一个STXXL函数时,磁盘文件会自动打开。因此必须将此类调用延迟到fork()之后,就像您在示例中所做的那样。

对于STXXL 1.4.0,您还可以在.STXXL配置文件中使用“###”。打开文件时,“###”将替换为当前pid


请注意,当调用第一个STXXL函数时,磁盘文件会自动打开。因此必须将此类调用延迟到fork()之后,就像您在示例中所做的那样。

我自己找到了答案,解决方案是为每个线程提供自己的虚拟磁盘,我这样做:

  stxxl::config * cfg = stxxl::config::get_instance();

  std::string result; 
  std::ostringstream convert; 
  convert << id; // the id of the stream, to make th filenames different
  result = convert.str(); 
    std::string base_file = "/var/tmp/stxxl" + result;
  stxxl::disk_config disk1(base_file, 100 * 1024 * 1024, "syscall autogrow delete_on_exit");

  cfg->add_disk(disk1);
stxxl::config*cfg=stxxl::config::get_instance();
std::字符串结果;
std::ostringstream转换;
转换添加盘(disk1);

我自己找到了答案,解决方案是给每个线程提供自己的虚拟磁盘,我这样做:

  stxxl::config * cfg = stxxl::config::get_instance();

  std::string result; 
  std::ostringstream convert; 
  convert << id; // the id of the stream, to make th filenames different
  result = convert.str(); 
    std::string base_file = "/var/tmp/stxxl" + result;
  stxxl::disk_config disk1(base_file, 100 * 1024 * 1024, "syscall autogrow delete_on_exit");

  cfg->add_disk(disk1);
stxxl::config*cfg=stxxl::config::get_instance();
std::字符串结果;
std::ostringstream转换;
转换添加盘(disk1);

如果你想回答自己的问题,请将其标记为已接受。如果你想回答自己的问题,请将其标记为已接受。这比我提出的更可怕:)主要是因为如果程序崩溃,那么####文件就会到处乱放。当这种情况经常发生时,人们开始想知道他们的数据在哪里这比我想到的更可怕:)主要是因为如果一个程序崩溃了,####文件就会到处乱放。当这种情况经常发生时,人们开始怀疑他们所有的磁盘空间都到哪里去了。