added assertion thread exists

This commit is contained in:
Phuntsok Drak-pa 2018-04-26 13:56:43 +02:00
parent b7f96f0557
commit 311898b363

View File

@ -3,19 +3,20 @@
* \brief Implementation of compression * \brief Implementation of compression
*/ */
#include "compress.hh"
#include "utf8.hh"
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <thread>
#ifdef Debug #ifdef Debug
constexpr bool debug_mode = true; constexpr bool debug_mode = true;
#else #else
constexpr bool debug_mode = false; constexpr bool debug_mode = false;
#endif #endif
#include "compress.hh"
#include "utf8.hh"
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <thread>
using dict_t = std::map<std::pair<uint32_t, uint8_t>, uint32_t>; using dict_t = std::map<std::pair<uint32_t, uint8_t>, uint32_t>;
using ustring = std::basic_string<uint8_t>; // chaîne non encodée using ustring = std::basic_string<uint8_t>; // chaîne non encodée
using uvec = std::vector<uint32_t>; // chaîne encodée using uvec = std::vector<uint32_t>; // chaîne encodée
@ -106,10 +107,10 @@ void compress(const std::string &t_in_file, const char *t_out_file) {
std::vector<char> chunk(32768, 0); std::vector<char> chunk(32768, 0);
while (input_file.read(chunk.data(), while (input_file.read(chunk.data(),
static_cast<std::streamsize>(chunk.size()))) { static_cast<std::streamsize>(chunk.size()))) {
printf("\n");
threads.emplace_back(nullptr, uvec{}); threads.emplace_back(nullptr, uvec{});
threads.back().first = std::make_unique<std::thread>( threads.back().first = std::make_unique<std::thread>(
std::thread{lzw_compress, chunk, ref(threads.back().second)}); std::thread{lzw_compress, chunk, ref(threads.back().second)});
assert(threads.back().first);
if (threads.size() >= 8) { if (threads.size() >= 8) {
join_and_write(threads, out); join_and_write(threads, out);
} }