下面的程序,与
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这看起来很像我的两个线程试图使用相同的文件处理程序/文件来更新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;
}发布于 2014-01-20 16:47:12
使用STXXL1.4.0,您还可以在###配置文件中使用“.stxxl”。打开文件时,"###“被替换为当前的pid。
注意,当调用第一个STXXL函数时,会自动打开磁盘文件。因此,必须将此类调用推迟到fork()之后,就像您在示例中所做的那样。
发布于 2014-01-20 19:19:20
我找到了答案,我自己,一个解决方案是给每个线程自己的虚拟磁盘,这个我已经这样做了:
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);https://stackoverflow.com/questions/21222783
复制相似问题