<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr - keigoi</title>
<link>http://snipplr.com/users/keigoi</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Sun, 19 May 2013 17:06:07 GMT</pubDate>
<item>
<title>(Haskell) recursive type representation in type level</title>
<link>http://snipplr.com/view/23403/recursive-type-representation-in-type-level/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 19 Nov 2009 10:38:02 GMT</pubDate>
<guid>http://snipplr.com/view/23403/recursive-type-representation-in-type-level/</guid>
</item>
<item>
<title>(C) pthread sleeper fairness</title>
<link>http://snipplr.com/view/19655/pthread-sleeper-fairness/</link>
<description><![CDATA[ <p>this snippet is for checking fairness of context switching in your environment.the snippet does not runs two threads directly, but it switches two threads explicitly, by using a monitor (a mutex and a condition variable).Some programming languges take such indirect concurrent execution mechanism  for native threads. Programming languges which support \"native threads\" but does not support conccurent GC must stop the whole process in order to collect garbages safely. Since native threads generally are not capable of disabling preemption, the runtime must pause all threads except for one that runs GC. compile with:gcc -lpthread filename.cthere is a `global lock\' and two threads. each thread runs work() in the same way, only except its parameter. each of two threads increments the counter hit_count[i] where i is the id of the thread.after 1 second, the program outputs statistics and terminates.SIGALRM. thread0: 1899, thread1: 2333, switch:20if your pthread library is fair, the first two numbers are nearly equal to each other, and the third number is 20 or so.unfortunately, my Mac OS X (10.5.8) has turned to be unfair:SIGALRM. thread0: 4086, thread1: 215, switch:2on the contrary, linux (debian 5.0, kenel 2.6.26) has shown to be fair. please post your results in the comments.The linux kernel 2.6 (>= 2.6.23) is likely to be fair, because it is equipped with the Completely Fair Scheduler. This scheduler is aware of \'sleeper fairness\'.see also:http://snipplr.com/view/19509/ if your pthread is shown to be \'unfair\', this O\'Caml snippet will also stops for a while.UPDATE:  added volatile to the shared variables.</p> ]]></description>
<pubDate>Sun, 13 Sep 2009 09:12:58 GMT</pubDate>
<guid>http://snipplr.com/view/19655/pthread-sleeper-fairness/</guid>
</item>
<item>
<title>(Other) OCaml memory allocation and context switching</title>
<link>http://snipplr.com/view/19509/ocaml-memory-allocation-and-context-switching/</link>
<description><![CDATA[ <p>OCaml runtime is known to do context switch at the point allocation occurs (confirmed on current version 3.11.1).
This snippet shows that context switch never occurs if the thread does not do any allocation, i/o nor synchronization.
compile with:

ocamlopt -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml

the function allocation allocates some memory on OCaml side, while allocation2 does on C side. 
In latter case allocation never occur on OCaml side, hence context doesn't switch, and one of the thread runs forever, while the other starves.

See also:http://snipplr.com/view/19485/</p> ]]></description>
<pubDate>Thu, 10 Sep 2009 12:04:25 GMT</pubDate>
<guid>http://snipplr.com/view/19509/ocaml-memory-allocation-and-context-switching/</guid>
</item>
<item>
<title>(Other) OCaml threads context switch example</title>
<link>http://snipplr.com/view/19485/ocaml-threads-context-switch-example/</link>
<description><![CDATA[ <p>this example checks that when the context switch occurs in the O'Caml runtime.
compile it with:


ocamlc -vmthread -I +threads -I unix unix.cmxa threads.cmxa filename.ml
ocamlc -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml
ocamlopt -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml


both 1. and 2. terminates, while 3. not (on my OCaml 3.11.1, on Mac OS X).

See also:http://snipplr.com/view/19509/</p> ]]></description>
<pubDate>Thu, 10 Sep 2009 04:34:04 GMT</pubDate>
<guid>http://snipplr.com/view/19485/ocaml-threads-context-switch-example/</guid>
</item>
<item>
<title>(Haskell) Networking sample in Haskell</title>
<link>http://snipplr.com/view/17541/networking-sample-in-haskell/</link>
<description><![CDATA[ <p>very basic example to connect/listen/accept on a port.</p> ]]></description>
<pubDate>Mon, 27 Jul 2009 19:33:12 GMT</pubDate>
<guid>http://snipplr.com/view/17541/networking-sample-in-haskell/</guid>
</item>
<item>
<title>(Haskell) Single line textbox in wxHaskell</title>
<link>http://snipplr.com/view/17539/single-line-textbox-in-wxhaskell/</link>
<description><![CDATA[ <p>This snippet shows you how to create a single-line text box, or how to use windowGetWindowStyleFlag.
Press enter to put text in the textbox into the console.</p> ]]></description>
<pubDate>Mon, 27 Jul 2009 18:55:46 GMT</pubDate>
<guid>http://snipplr.com/view/17539/single-line-textbox-in-wxhaskell/</guid>
</item>
<item>
<title>(Haskell) wxHaskell multi-thread &amp;amp; custom event example</title>
<link>http://snipplr.com/view/17538/wxhaskell-multithread--custom-event-example/</link>
<description><![CDATA[ <p>This examples shows how to handle user-defined events in wxHaskell via menu events.

If the thread issues an event is not the main thread, use evtHandlerAddPendingEvent instead of evtHandlerProcessEvent.</p> ]]></description>
<pubDate>Mon, 27 Jul 2009 18:50:20 GMT</pubDate>
<guid>http://snipplr.com/view/17538/wxhaskell-multithread--custom-event-example/</guid>
</item>
</channel>
</rss>