MantisBT - Open CASCADE
View Issue Details
0030430Open CASCADE[OCCT] OCCT:DRAWpublic2019-01-03 12:352019-01-12 14:42
abv 
bugmaster 
normalminor 
verifiedfixed 
[OCCT] 7.3.0 
[OCCT] 7.4.0 
demo/draw/bug30430
0030430: Draw - command testgrid in parallel mode hangs if DRAW is launched without GUI
It is impossible to run testgrid command in parallel mode using DRAW option -f (or -c): it just hangs.

The problem has been identified after fix of 0030377, however it does exist in all versions of OCCT that I have tried (6.8.0 till current), and for all tested versions of Tcl (including ActiveTcl 8.6, standard Tcl 8.6.4, 8.6.8, 8.7.0a - all built from sources).

The symptoms are as follows.

1. The test script succeeds in creating thread pool and setting up jobs, and hangs on waiting for jobs to complete. If job script is replaced by some Tcl command instead of exec (e.g. puts), it works fine. The jobs hangs only when it contains "exec" command, and does hang regardless of what executable is used (I have tried "git status" - just the same as executed successfully in the beginning of the testgrid command, and it hangs in the same way as DRAWEXE).

2. Under debugger, the execution successfully goes to creation of the process (in tclWinPipe.c, function TclpCreateProcess()): CreateProcess returns non-zero and yields some non-zero PID. The program then waits infinitely in

3. If non-existing command is fed to exec instead of DRAWEXE, the jobs complete correctly (all tests fail) but execution hangs in tpool::release again waiting for some events (threadPoolCmd.c, function TpoolRelease())

4. Testgrid works OK if Tk_Init() is called (it is called when DRAW is executed interactively but not with -c or -f options -- in that case it sets variable Draw_VirtualWindows to true an skips initialization of Tk). If DRAW is built without Tk at all, testgrid hangs in the same way.

In Tk_Init(), the crucial point looks to be the call to TkListCreateFrame(): if it is bypassed (in debugger), the hang up is reproduced.

5. Testgrid works OK if DRAW runs in batch mode, i.e. without creation of separate thread for evaluation of Tcl commands. That mode can be enabled by option -b, but requires patch for 0030377 to work.
1. Create file "testgrid.tcl" containing single line "testgrid demo draw -overwrite"

2. Modify draw.bat adding arguments to DRAWEXE:

DRAWEXE -f path/to/testgrid.tcl

3. Launch draw.bat
No tags attached.
related to 0030377verified bugmaster DRAW, Windows - command executed via option -c fails on puts 
? bug30430.tcl (1,006) 2019-01-07 13:12
https://tracker.dev.opencascade.org/
Issue History
2019-01-03 12:35abvNew Issue
2019-01-03 12:35abvAssigned To => abv
2019-01-04 00:38abvDescription Updatedbug_revision_view_page.php?rev_id=20516#r20516
2019-01-07 13:12abvFile Added: bug30430.tcl
2019-01-07 13:15abvNote Added: 0081685
2019-01-08 21:31abvDescription Updatedbug_revision_view_page.php?rev_id=20521#r20521
2019-01-10 08:20gitNote Added: 0081700
2019-01-10 10:41abvRelationship addedrelated to 0030377
2019-01-10 10:44abvNote Added: 0081702
2019-01-10 10:44abvAssigned Toabv => kgv
2019-01-10 10:44abvStatusnew => resolved
2019-01-10 11:28kgvNote Added: 0081706
2019-01-10 11:28kgvAssigned Tokgv => bugmaster
2019-01-10 11:28kgvStatusresolved => reviewed
2019-01-10 11:28kgvProduct Version => 7.3.0
2019-01-10 16:32bugmasterTest case number => demo/draw/bug30430
2019-01-10 16:36bugmasterNote Added: 0081720
2019-01-10 16:36bugmasterStatusreviewed => tested
2019-01-12 14:34bugmasterChangeset attached => occt master 8de8dacd
2019-01-12 14:34bugmasterStatustested => verified
2019-01-12 14:34bugmasterResolutionopen => fixed
2019-01-12 14:42gitNote Added: 0081765

Notes
(0081685)
abv   
2019-01-07 13:15   
Attached script bug30430.tcl demonstrates the problem (the same or very similar) without any OCCT-specific commands, using pure Tcl code. It works fine in Tcl shell (tclsh.exe bug30340.tcl) or in DRAW if launched in interactive mode (with option -i), but hangs on releasing thread pools if DRAW is executed without TK (non-interactive mode, virtual windows).
(0081700)
git   
2019-01-10 08:20   
Branch CR30430 has been created by abv.

SHA-1: b727d25e54c44a99efb9aa2c15236ef8c36b9f92


Detailed log of new commits:

Author: abv
Date: Thu Jan 10 08:17:04 2019 +0300

    0030430: Draw - command testgrid in parallel mode hangs if DRAW is launched without GUI
    
    Ensure that initialization of Tcl interpretor is performed in the same thread where commands are evaluated.
    
    Added test demo draw bug30430

Author: abv
Date: Sun Nov 18 19:53:10 2018 +0300

    0030377: DRAW, Windows - command executed via option -c fails on puts
    
    When DRAW on Windows is launched with option -c, the command is now properly transferred to Tcl thread (separate thread that runs Tcl interpretor on Windows except when DRAW is run in batch mode) for execution, instead of being evaluated in the main thread.
    
    Execution of DRAW in batch mode (option -b) is fixed by enabling proper initialization of the Tcl interpretor and replacement of backslashes in path to startup script by straight slashes on Windows in that mode.
    
    Declaration of global variables used for communication of console command between threads is moved to Draw_Window.hxx to ensure consistency.
    Function wscpy_s is used instead of memcpy to avoid possible buffer overrun.
(0081702)
abv   
2019-01-10 10:44   
Fix is pushed (together with fix for 0030377) to branch CR30430 and tested, see Jenkins job CR30430-master. Please review.
(0081706)
kgv   
2019-01-10 11:28   
Please take the patch.
(0081720)
bugmaster   
2019-01-10 16:36   
Combination -
OCCT branch : CR30430 SHA - b727d25e54c44a99efb9aa2c15236ef8c36b9f92
Products branch : master SHA - 0b9df64a156abd5cbfbfccb15967b46cdabfe1f8
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 16384.390000000094 / 16363.880000000001 [+0.13%]
Products
Total CPU difference: 7178.450000000044 / 7172.62000000003 [+0.08%]
Windows-64-VC14:
OCCT
Total CPU difference: 17734.359375 / 17727.875 [+0.04%]
Products
Total CPU difference: 8593.5625 / 8592.53125 [+0.01%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
(0081765)
git   
2019-01-12 14:42   
Branch CR30430 has been deleted by inv.

SHA-1: b727d25e54c44a99efb9aa2c15236ef8c36b9f92