@@ -48,6 +48,24 @@ namespace graphlab {
4848
4949using namespace query_eval ;
5050
51+ static std::shared_ptr<sarray<flexible_type>> get_empty_sarray () {
52+ // make empty sarray and keep it around, reusing it whenever
53+ // I need an empty sarray . We are intentionally leaking this object.
54+ // Otherwise the termination of this will race against the cleanup of the
55+ // cache files.
56+ static std::shared_ptr<sarray<flexible_type> >* empty_sarray = nullptr ;
57+ static graphlab::mutex static_sa_lock;
58+ std::lock_guard<graphlab::mutex> guard (static_sa_lock);
59+ if (empty_sarray == nullptr ) {
60+ empty_sarray = new std::shared_ptr<sarray<flexible_type>>();
61+ (*empty_sarray) = std::make_shared<sarray<flexible_type>>();
62+ (*empty_sarray)->open_for_write (1 );
63+ (*empty_sarray)->set_type (flex_type_enum::FLOAT);
64+ (*empty_sarray)->close ();
65+ }
66+ return *empty_sarray;
67+ }
68+
5169unity_sarray::unity_sarray () {
5270 // make empty sarray and keep it around, reusing it whenever
5371 // I need an empty sarray
@@ -288,17 +306,8 @@ void unity_sarray::save_array_by_index_file(std::string index_file) {
288306}
289307
290308void unity_sarray::clear () {
291- static std::shared_ptr<sarray<flexible_type> > empty_sarray;
292- static graphlab::mutex static_sa_lock;
293- std::lock_guard<graphlab::mutex> guard (static_sa_lock);
294- if (empty_sarray == nullptr ) {
295- empty_sarray = std::make_shared<sarray<flexible_type>>();
296- empty_sarray->open_for_write (1 );
297- empty_sarray->set_type (flex_type_enum::FLOAT);
298- empty_sarray->close ();
299- }
300309 m_planner_node =
301- query_eval::op_sarray_source::make_planner_node (empty_sarray );
310+ query_eval::op_sarray_source::make_planner_node (get_empty_sarray () );
302311}
303312
304313void unity_sarray::save (oarchive& oarc) const {
0 commit comments