Re: [Factor-talk] Issue #1573: interrupt a tight loop

2016-05-28 Thread Alexander Ilin
Hello!

28.05.2016, 14:14, "Björn Lindqvist" :
> Hello,
>
> Here is some sample code to run:
>
> USING: alien io kernel threads.private windows.kernel32
> windows.types ;
> IN: examples.windows.threads
>
> : eternity ( -- ) eternity ;
>
> :  ( -- alien )
> DWORD { LPVOID } stdcall [ drop eternity 0 ] alien-callback ;
>
> : start-thread ( -- handle )
> f 0  f 0 f CreateThread ;
>
> : main ( -- )
> start-thread drop
> "I am here" print flush
> 20,000,000,000 (sleep) ;
>
> MAIN: main
>
> As you can see, it taxes the cpu 100% which proves that the thread is
> running. Then something triggers a gc and it crashes. It is not
> unexpected.

  I see now. I've modified the main word to contain "start-thread drop 
eternity", and it doesn't crash. I see two threads happily busy forever. This 
means that the code works. It was confusing for me before this experiment, 
because what I saw was an instant crash. I guess the reason must be that GC is 
called all the time by the UI (maybe it's specific to Windows implementation). 
And if you don't get back to the UI, no GC, no crash.

  At least that's a theory one can work with. Let's assume it's the GC's fault.

> You are kind of entering unexplored territory here. No one has ensured
> that factor works correctly when running kernel threads containing
> factor code. You aren't meant to do it.

  I remember in Slava's Google Talk there were some plans for native 
multithreading...
  https://www.youtube.com/watch?v=f_0QlhYlS8g

> However, you can start and run a thread written in C++ in the VM using
> start_thread() as long as you are careful not to mess with the
> factor_vm object in unapproved ways. You can see how it is done in
> start_sampling_profiler_timer() in vm/os-windows.cpp.

  Yes, I'll have to try that approach, although it would've been cool to stick 
to the higher level language.
  OTOH, maybe that kind of functionality does belong in the VM.

> I still don't understand how you can get that thread to trap the
> ctrl+break key combo. But if you can, then great!

---=---
 Александр

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Issue #1573: interrupt a tight loop

2016-05-28 Thread Alexander Ilin
Thank you, Björn, I'll give that a try.

In the meantime, has anyone tried debugging the VM under Visual Studio 2015? 
The build tool is command-line, and I see no VS solution file.

28.05.2016, 14:14, "Björn Lindqvist" :
> Hello,
>
> Here is some sample code to run:
>
> USING: alien io kernel threads.private windows.kernel32
> windows.types ;
> IN: examples.windows.threads
>
> : eternity ( -- ) eternity ;
>
> :  ( -- alien )
> DWORD { LPVOID } stdcall [ drop eternity 0 ] alien-callback ;
>
> : start-thread ( -- handle )
> f 0  f 0 f CreateThread ;
>
> : main ( -- )
> start-thread drop
> "I am here" print flush
> 20,000,000,000 (sleep) ;
>
> MAIN: main
>
> As you can see, it taxes the cpu 100% which proves that the thread is
> running. Then something triggers a gc and it crashes. It is not
> unexpected.
>
> You are kind of entering unexplored territory here. No one has ensured
> that factor works correctly when running kernel threads containing
> factor code. You aren't meant to do it.
>
> However, you can start and run a thread written in C++ in the VM using
> start_thread() as long as you are careful not to mess with the
> factor_vm object in unapproved ways. You can see how it is done in
> start_sampling_profiler_timer() in vm/os-windows.cpp.
>
> I still don't understand how you can get that thread to trap the
> ctrl+break key combo. But if you can, then great!
>
> 2016-05-27 22:16 GMT+02:00 Alexander Ilin :
>>  Hello!
>>
>>  27.05.2016, 20:00, "Björn Lindqvist" :
>>>  Try defining  like this:
>>>
>>>  :  ( -- alien ) DWORD { LPVOID } stdcall [ ] alien-callback ;
>>
>>    Tried this, see below.
>>
>>    I'm now at home, trying these things on Win 8.1 64-bit, on a freshly 
>> bootstrapped Factor. (For some reason the build.cmd produced a 32-bit 
>> executable, even though I'm on a 64-bit system.) The Windows Error Reporting 
>> tool (WerFault.exe) says that an exception is happening. Sometimes I get to 
>> see some kind of dumps in the console, sometimes not.
>>
>>    Here's my code:
>>
>>  USING: kernel windows.kernel32
>>  alien alien.data alien.syntax windows.types ;
>>  IN: my-thd
>>
>>  LIBRARY: kernel32
>>
>>  FUNCTION: HANDLE CreateThread ( LPSECURITY_ATTRIBUTES lpThreadAttributes,
>>  SIZE_T dwStackSize,
>>  LPVOID lpStartAddress,
>>  LPVOID lpParameter,
>>  DWORD dwCreationFlags,
>>  LPDWORD lpThreadId )
>>
>>  CALLBACK: DWORD ThreadProc ( LPVOID lpParameter )
>>
>>  :  ( -- alien )
>>    [ [ t ] [ ] while ] ThreadProc ;
>>
>>  :  ( -- alien )
>>    DWORD { LPVOID } stdcall [ ] alien-callback ;
>>
>>  :  ( -- alien )
>>    DWORD { LPVOID } stdcall [ [ t ] [ ] while ] alien-callback ;
>>
>>  : start-thd ( -- hnd )
>>  f 0  f 0 f CreateThread ;
>>
>>  : start-thd-2 ( -- hnd )
>>  f 0  f 0 f CreateThread ;
>>
>>  : start-thd-3 ( -- hnd )
>>  f 0  f 0 f CreateThread ;
>>
>>    Test runs and results:
>>    start-thd: the app sometimes dies with no output. WerFault sometimes 
>> reports Exception Code c409, which Googles to "Stack buffer overflow", 
>> and sometimes c005, which is "access violation". Sometimes I see a 
>> console dump, which starts with "fatal_error: Memory protection fault during 
>> gc: ".
>>
>>    start-thd-2: most of the time dies with no output, but once I saw the 
>> text "Error in print-error!" on the console.
>>
>>    start-thd-3: most of the time dies with no output, but once I saw a 
>> message box with "Memory protection fault at address 0x105" in it.
>>
>>    Can you help me? I need more code to try.

---=---
 Александр

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Issue #1573: interrupt a tight loop

2016-05-28 Thread Björn Lindqvist
Hello,

Here is some sample code to run:

USING: alien io kernel threads.private windows.kernel32
windows.types ;
IN: examples.windows.threads

: eternity ( -- ) eternity ;

:  ( -- alien )
DWORD { LPVOID } stdcall [ drop eternity 0 ] alien-callback ;

: start-thread ( -- handle )
f 0  f 0 f CreateThread ;

: main ( -- )
start-thread drop
"I am here" print flush
20,000,000,000 (sleep) ;

MAIN: main

As you can see, it taxes the cpu 100% which proves that the thread is
running. Then something triggers a gc and it crashes. It is not
unexpected.

You are kind of entering unexplored territory here. No one has ensured
that factor works correctly when running kernel threads containing
factor code. You aren't meant to do it.

However, you can start and run a thread written in C++ in the VM using
start_thread() as long as you are careful not to mess with the
factor_vm object in unapproved ways. You can see how it is done in
start_sampling_profiler_timer() in vm/os-windows.cpp.

I still don't understand how you can get that thread to trap the
ctrl+break key combo. But if you can, then great!


2016-05-27 22:16 GMT+02:00 Alexander Ilin :
> Hello!
>
> 27.05.2016, 20:00, "Björn Lindqvist" :
>> Try defining  like this:
>>
>> :  ( -- alien ) DWORD { LPVOID } stdcall [ ] alien-callback ;
>
>   Tried this, see below.
>
>   I'm now at home, trying these things on Win 8.1 64-bit, on a freshly 
> bootstrapped Factor. (For some reason the build.cmd produced a 32-bit 
> executable, even though I'm on a 64-bit system.) The Windows Error Reporting 
> tool (WerFault.exe) says that an exception is happening. Sometimes I get to 
> see some kind of dumps in the console, sometimes not.
>
>   Here's my code:
>
> USING: kernel windows.kernel32
> alien alien.data alien.syntax windows.types ;
> IN: my-thd
>
> LIBRARY: kernel32
>
> FUNCTION: HANDLE CreateThread ( LPSECURITY_ATTRIBUTES lpThreadAttributes,
> SIZE_T dwStackSize,
> LPVOID lpStartAddress,
> LPVOID lpParameter,
> DWORD dwCreationFlags,
> LPDWORD lpThreadId )
>
> CALLBACK: DWORD ThreadProc ( LPVOID lpParameter )
>
> :  ( -- alien )
>   [ [ t ] [ ] while ] ThreadProc ;
>
>
> :  ( -- alien )
>   DWORD { LPVOID } stdcall [ ] alien-callback ;
>
> :  ( -- alien )
>   DWORD { LPVOID } stdcall [ [ t ] [ ] while ] alien-callback ;
>
>
> : start-thd ( -- hnd )
> f 0  f 0 f CreateThread ;
>
> : start-thd-2 ( -- hnd )
> f 0  f 0 f CreateThread ;
>
> : start-thd-3 ( -- hnd )
> f 0  f 0 f CreateThread ;
>
>   Test runs and results:
>   start-thd: the app sometimes dies with no output. WerFault sometimes 
> reports Exception Code c409, which Googles to "Stack buffer overflow", 
> and sometimes c005, which is "access violation". Sometimes I see a 
> console dump, which starts with "fatal_error: Memory protection fault during 
> gc: ".
>
>   start-thd-2: most of the time dies with no output, but once I saw the text 
> "Error in print-error!" on the console.
>
>   start-thd-3: most of the time dies with no output, but once I saw a message 
> box with "Memory protection fault at address 0x105" in it.
>
>   Can you help me? I need more code to try.
>
> ---=---
>  Александр
>
> --
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity
> planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk



-- 
mvh/best regards Björn Lindqvist

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Issue #1573: interrupt a tight loop

2016-05-28 Thread Alexander Ilin
Hello!

  Also, sometimes trying to run
USE: my-thd start-thd
  I get a message box saying "Memory protection fault at address 0x", 
and then I can inspect things at the Factor's console window. In these cases I 
see something like this on the Data Stack:
1057
{ 64199 16 8 f }

  The number in the first line randomly changes in the range about 1050..1115.
  The second to last number in the sequence (8 in the example above) is the 
same number that is the address of the memory protection fault in the message 
box.
  The first and last items of the sequence (64199 and f) are always the same.
  In place of 16 I saw similarly small even numbers: 10, 12, 16, 8.

28.05.2016, 13:26, "Alexander Ilin" :
> Hello!
>
>   A fun observation. Sometimes, when the Factor application is not 
> immediately terminated and an error dialog is shown on screen, I can inspect 
> it with the Process Explorer and see that my busy-loop thread is in there, 
> created and running.
>
> 27.05.2016, 23:16, "Alexander Ilin" :
>>  Hello!
>>
>>  27.05.2016, 20:00, "Björn Lindqvist" :
>>>   Try defining  like this:
>>>
>>>   :  ( -- alien ) DWORD { LPVOID } stdcall [ ] alien-callback ;
>>
>>    Tried this, see below.
>>
>>    I'm now at home, trying these things on Win 8.1 64-bit, on a freshly 
>> bootstrapped Factor. (For some reason the build.cmd produced a 32-bit 
>> executable, even though I'm on a 64-bit system.) The Windows Error Reporting 
>> tool (WerFault.exe) says that an exception is happening. Sometimes I get to 
>> see some kind of dumps in the console, sometimes not.
>>
>>    Here's my code:
>>
>>  USING: kernel windows.kernel32
>>  alien alien.data alien.syntax windows.types ;
>>  IN: my-thd
>>
>>  LIBRARY: kernel32
>>
>>  FUNCTION: HANDLE CreateThread ( LPSECURITY_ATTRIBUTES lpThreadAttributes,
>>  SIZE_T dwStackSize,
>>  LPVOID lpStartAddress,
>>  LPVOID lpParameter,
>>  DWORD dwCreationFlags,
>>  LPDWORD lpThreadId )
>>
>>  CALLBACK: DWORD ThreadProc ( LPVOID lpParameter )
>>
>>  :  ( -- alien )
>>    [ [ t ] [ ] while ] ThreadProc ;
>>
>>  :  ( -- alien )
>>    DWORD { LPVOID } stdcall [ ] alien-callback ;
>>
>>  :  ( -- alien )
>>    DWORD { LPVOID } stdcall [ [ t ] [ ] while ] alien-callback ;
>>
>>  : start-thd ( -- hnd )
>>  f 0  f 0 f CreateThread ;
>>
>>  : start-thd-2 ( -- hnd )
>>  f 0  f 0 f CreateThread ;
>>
>>  : start-thd-3 ( -- hnd )
>>  f 0  f 0 f CreateThread ;
>>
>>    Test runs and results:
>>    start-thd: the app sometimes dies with no output. WerFault sometimes 
>> reports Exception Code c409, which Googles to "Stack buffer overflow", 
>> and sometimes c005, which is "access violation". Sometimes I see a 
>> console dump, which starts with "fatal_error: Memory protection fault during 
>> gc: ".
>>
>>    start-thd-2: most of the time dies with no output, but once I saw the 
>> text "Error in print-error!" on the console.
>>
>>    start-thd-3: most of the time dies with no output, but once I saw a 
>> message box with "Memory protection fault at address 0x105" in it.
>>
>>    Can you help me? I need more code to try.
>
> ---=---
>  Александр
>
> --
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity
> planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=---
 Александр

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Issue #1573: interrupt a tight loop

2016-05-28 Thread Alexander Ilin
Hello, John! 28.05.2016, 00:10, "John Benediktsson" : IIRC, there are x86 (32-bit) and x64 (64-bit) versions of some of the VS Command Prompt shortcuts and they setup environment variables that will cause a 32-bit or 64-bit factor to be produced. Ah, good point. That might be it. ---=---Александр 

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk