On Tue Nov 01 09:01:04 2016, cookbook_...@yahoo.co.jp wrote:
> I'm creating a Perl 6 bindings for
> MeCab ( http://taku910.github.io/mecab/ )
> 
> See the following codes and documentations(translations).
> 
> My repository is:
> https://github.com/titsuki/p6-MeCab/tree/for-RT
> 
> 
> The following subtest in the t/02-lattice.t in the above repository is
> hung up.
> ----
> subtest {
>     my MeCab::Model $model .= new;
>     my @texts = (("私","僕") xx 3).flat;
> 
>     my @actual = (@texts.hyper(:batch(1))\
>                   .map(
>                          {
>                              my MeCab::Tagger $tagger = $model.create-
> tagger;
>                              my MeCab::Lattice $lattice =
> $model.create-lattice;
>                              $lattice.sentence($_);
>                              $lattice.tostr if
> $tagger.parse($lattice);
>                              $tagger.DESTROY;
>                              $lattice.DESTROY;
>                          }
>                      ).list);
> 
>     my Str $r1 = ("私\t名詞,代名詞,一般,*,*,*,私,ワタシ,ワタシ\nEOS\n");
>     my Str $r2 = ("僕\t名詞,代名詞,一般,*,*,*,僕,ボク,ボク\nEOS\n");
>     my @expected = (($r1, $r2) xx 3).flat;
>     is @actual, @expected;
> }, "MeCab::Tagger should work in the multithread environment";
> ---
> 
> 
> In the MeCab documentation
> page(Japanese) https://taku910.github.io/mecab/libmecab.html
> "C++ サンプルコード" (en: C++ sample code) section says that:
> In the multithread environment (MeCab::Tagger, MeCab::Model,
> MeCab::Lattice)
> 
> * Call MeCab::createModel() and create the Model object.
> 
> * Call model->createTagger and create the Tagger object. The Tagger
> objects share the same model, even though you create the multiple
> models under the one model per thread constraint.
> 
> * Call model->createLattice or MeCab::createLattice() and crate the
> Lattice object. The Lattice objects include all local variables for
> the morpheme analyze. Must keep the constraint that you can create
> only one object per thread.
> 
> * model->swap(antoher_model) function replaces the Tagger object
> models created from the invocant model by another_model. This
> operation is thread-safe.
> 
> 
> 
> 
> I think I properly call the MeCab functions from Perl 6(e.g.
> $model.create-tagger, $model.create-lattice) according to the above
> instructions.
>     So I think something is wrong in the NativeCall.

I think the hang was due to long-running native functions called on one thread 
blocking GC (and thus progress) in all other threads. That is addressed in 
https://github.com/MoarVM/MoarVM/commit/5c659178a07d86fe73b7c506c4ea7b10ad38b0e8
 and 
https://github.com/MoarVM/MoarVM/commit/f769569b78f099d59b7a17966d9096a0837c4d42
 and tested in 
https://github.com/rakudo/rakudo/commit/5ba75f445dc74560f9dabceeb4b4dc13f78c786f.

If you still have problems, please re-open this issue. Also, if possible, see 
if you can find a smaller reproduction (for example, try just running the code 
in a number of start blocks, or threads, instead of using `.hyper`).

Thanks,

/jnthn

Reply via email to