Hello! 28.05.2016, 14:14, "Björn Lindqvist" <bjou...@gmail.com>: > Hello, > > Here is some sample code to run: > > USING: alien io kernel threads.private windows.kernel32 > windows.types ; > IN: examples.windows.threads > > : eternity ( -- ) eternity ; > > : <ThreadProc> ( -- alien ) > DWORD { LPVOID } stdcall [ drop eternity 0 ] alien-callback ; > > : start-thread ( -- handle ) > f 0 <ThreadProc> 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