Hello,

I'm using threads and a tk gui. I know that I have to be careful with this because tk is not thread-safe.

So I created a thread before creating the tk gui. And my thread has an idle and a work state. Initially it is in the idle state. When pressing a generate button in the tk gui then the state (shared variable) is changed to work and a data structure is passed via a queue to the thread and the thread is doing its work. Afterwards it changes back to idle state.

Everything is working fine apart from the performance.

Here you see the data which is filled by my tk gui:

my %gen_data = ( lri => { major_version => 1, minor_version => 10, is_integration_flag_active => FALSE, module_id => 0x01, output_file => "D:/out.sre" }, pm => { major_version => 4, minor_version => 2, build_version => 82, input_file => "D:/in.s3" }, gp => { is_active => TRUE, major_version => 3, minor_version => 4, build_version => 7341, nb_bytes_data_field => 16, root_path => "D:/temp_path", tranche => T2 });

The main task in which tk is running is then doing the enqueuing. $ref_gen_data is a reference to the data structure filled via the tk gui.

# lri $q->enqueue($ref_gen_data->{'lri'}{'major_version'}, $ref_gen_data->{'lri'}{'minor_version'}, $ref_gen_data->{'lri'}{'is_integration_flag_active'}, $ref_gen_data->{'lri'}{'module_id'}, $ref_gen_data->{'lri'}{'output_file'}); # pm $q->enqueue($ref_gen_data->{'pm'}{'major_version'}, $ref_gen_data->{'pm'}{'minor_version'}, $ref_gen_data->{'pm'}{'build_version'}, $ref_gen_data->{'pm'}{'input_file'}); # gp $q->enqueue($ref_gen_data->{'gp'}{'is_active'}, $ref_gen_data->{'gp'}{'major_version'}, $ref_gen_data->{'gp'}{'minor_version'}, $ref_gen_data->{'gp'}{'build_version'}, $ref_gen_data->{'gp'}{'nb_bytes_data_field'}, $ref_gen_data->{'gp'}{'root_path'}, $ref_gen_data->{'gp'}{'tranche'});

The worker thread is doing the dequeuing to get the data.

my %gen_data; # lri $gen_data{'lri'}{'major_version'} = $q->dequeue(); $gen_data{'lri'}{'minor_version'} = $q->dequeue(); $gen_data{'lri'}{'is_integration_flag_active'} = $q->deque +ue(); $gen_data{'lri'}{'module_id'} = $q->dequeue(); $gen_data{'lri'}{'output_file'} = $q->dequeue(); # pm $gen_data{'pm'}{'major_version'} = $q->dequeue(); $gen_data{'pm'}{'minor_version'} = $q->dequeue(); $gen_data{'pm'}{'build_version'} = $q->dequeue(); $gen_data{'pm'}{'input_file'} = $q->dequeue(); # gp $gen_data{'gp'}{'is_active'} = $q->dequeue(); $gen_data{'gp'}{'major_version'} = $q->dequeue(); $gen_data{'gp'}{'minor_version'} = $q->dequeue(); $gen_data{'gp'}{'build_version'} = $q->dequeue(); $gen_data{'gp'}{'nb_bytes_data_field'} = $q->dequeue(); $gen_data{'gp'}{'root_path'} = $q->dequeue(); $gen_data{'gp'}{'tranche'} = $q->dequeue();

Now the summary: If I do it like this the thread is very slow. Algorithm needs about 1 hour.

I found out that the problem are the major and minor version of the gp. If I use the following code (replacing major and minor version of gp with sample values) for enqueuing the thread is working very fast (about 30s).

# lri $q->enqueue($ref_gen_data->{'lri'}{'major_version'}, $ref_gen_data->{'lri'}{'minor_version'}, $ref_gen_data->{'lri'}{'is_integration_flag_active'}, $ref_gen_data->{'lri'}{'module_id'}, $ref_gen_data->{'lri'}{'output_file'}); # pm $q->enqueue($ref_gen_data->{'pm'}{'major_version'}, $ref_gen_data->{'pm'}{'minor_version'}, $ref_gen_data->{'pm'}{'build_version'}, $ref_gen_data->{'pm'}{'input_file'}); # gp $q->enqueue($ref_gen_data->{'gp'}{'is_active'}, 3, 4, $ref_gen_data->{'gp'}{'build_version'}, $ref_gen_data->{'gp'}{'nb_bytes_data_field'}, $ref_gen_data->{'gp'}{'root_path'}, $ref_gen_data->{'gp'}{'tranche'});

It is so strange. Why is the thread so slow If I use the major and minor version of gp and why is it fast if I put in sample values instead. I do not understand why. I hope that you can give me some hints.

I also tried to use shared variables instead of the queue. But here was exactly the same behaviour.

The perl script is running on a windows xp.

Thank you very much in advance.

Dirk


In reply to Thread very slow by Dirk80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.