<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Comments for page &quot;Getting Rid of ZeroMQ-style Contexts&quot;</title>
		<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts</link>
		<description>Posts in the discussion thread &quot;Getting Rid of ZeroMQ-style Contexts&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 01 Aug 2015 21:48:44 +0000</lastBuildDate>
		
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1777643</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1777643</link>
				<description></description>
				<pubDate>Fri, 17 May 2013 19:44:07 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Wouldn't rigorously setting CLOEXEC on all fds do the job?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1777628</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1777628</link>
				<description></description>
				<pubDate>Fri, 17 May 2013 19:20:12 +0000</pubDate>
				<wikidot:authorName>erik</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Forking doesn't work well in 0mq. When fork()'ing, sockets are dup'ed, But the new (child) can't &quot;close&quot; them&#8230; because the context can't be reused. Then, if the parent tries to exit and reconnect, the dup'ed sockets block the bind() call.</p> <p>After a fork, user should call nm_postfork(MODE)</p> <p>Check to see if the pid associated with the socket is the same as the pid that opened it. if not, duplicated queues are cleared, and &quot;file descriptor based&quot; (tcp, unix) sockets are closed. All sockets are still valid in the child, but they are all &quot;closed&quot;.</p> <p>Especially when there are no &quot;contexts&quot; you need a way of handling fork()</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1774650</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1774650</link>
				<description></description>
				<pubDate>Tue, 14 May 2013 20:11:38 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Shut down is done when the last socket is closed. It requires some synchronisation kung-fu but it's doable.</p> <p>You are right about the title. I've changed it to &quot;ZeroMQ-style contexts&quot;.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1774646</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1774646</link>
				<description></description>
				<pubDate>Tue, 14 May 2013 20:09:20 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>1) Same behaviour is exhibited by zmq_term(). How do you handle it there? This is just moving it to close() function. That being said, the only non-half-assed (full-assed?) solution is to move the entire messaging layer into kernel space and thus allow it to send pending data even after the process it terminated.</p> <p>2) Global state is simply global, guarded by a mutex. However, the mutex is locked only when sockets are sreated or closed. The critical path (send/recv) doesn't touch the global state and thus requires no locking.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1774634</guid>
				<title>Re: Shutdown...</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1774634</link>
				<description></description>
				<pubDate>Tue, 14 May 2013 19:58:03 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The term() function still exists, but it is not longer a required step in the process shutdown. It is an optional utility that unblocks any blocking calls and causes nanomsg functions to return ETERM from that point on.</p> <p>Actual deallocation of the global resources happens when last socket is closed, irrespectively of whether nn_term() was used or not.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1774469</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1774469</link>
				<description></description>
				<pubDate>Tue, 14 May 2013 17:32:11 +0000</pubDate>
				<wikidot:authorName>pieterh</wikidot:authorName>				<wikidot:authorUserId>99</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Contexts were a design mistake, yes. There are use cases for them but they should not be part of the basic API. However you don't need blocking as far as I can tell. What most apps do, and what the API should do, is maintain one context by default. A static thread safe object. Making this visible to the user and asking the user to take control was too complex (especially when we still asked the user to specify how many i/o threads to use&#8230;)</p> <p>Still, with no contexts how do you shut-down the whole engine safely?</p> <p>BTW the title of your post is misleading, you are not getting rid of ZeroMQ contexts. :)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1774434</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1774434</link>
				<description></description>
				<pubDate>Tue, 14 May 2013 16:52:49 +0000</pubDate>
				<wikidot:authorName>zot</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Two comments:</p> <p>1)<br /> Every API calls needs to provide a non-blocking variant<br /> e.g. nn_close() always blocking will greatly complicate event-driven<br /> code that assumes no blocking&#8230;</p> <p>2)<br /> To avoid locking between threads, are you planning to use<br /> an implicit per-thread context (i.e. thread-local variable) in conjunction<br /> with the shared/locked global state?</p> <p>If the core of the library makes use of a context, then many options are possible:</p> <p>1) Provide a shared implicit context for the entire process<br /> + the simple API you outlined above that uses the global context</p> <p>2) An implicit per-thread context (totally independent or shared between some threads)</p> <p>3) Multiple independent contexts under full programmer control</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-652544#post-1774357</guid>
				<title>Shutdown...</title>
				<link>http://250bpm.com/forum/t-652544/getting-rid-of-zeromq-style-contexts#post-1774357</link>
				<description></description>
				<pubDate>Tue, 14 May 2013 15:34:30 +0000</pubDate>
				<wikidot:authorName>jhawk28</wikidot:authorName>				<wikidot:authorUserId>865475</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>How do you plan on shutdown?</p> <p>In ZeroMQ for example, I often setup different threads to handle various sockets. The threads will just listen for data and process it (think something like a worker thread). In ZeroMQ, we currently have a context.term(). This interrupts any threads or pollers to throw a ZMQException (in Java). I can then catch the exception and call socket.close() in each thread and close out the loops.</p> <p>A possible solution is for the socket.close() to be thread-safe. I can then close the sockets from my main thread.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>