<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/c/tags/signal</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Tue, 21 May 2013 02:33:20 GMT</pubDate>
<item>
<title>(C) Simple Linux signal handler - sukantahazra</title>
<link>http://snipplr.com/view/28341/simple-linux-signal-handler/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 15 Feb 2010 12:31:55 GMT</pubDate>
<guid>http://snipplr.com/view/28341/simple-linux-signal-handler/</guid>
</item>
<item>
<title>(C) pthread sleeper fairness - keigoi</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>
</channel>
</rss>