[{"data":1,"prerenderedAt":339},["ShallowReactive",2],{"project-8244815":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":29,"sentiment":30,"stance_mix":31,"scored_comments":35,"aspects":36,"strip":42,"post_text":44,"what":45,"said":85,"maker_in_thread":182,"shape":192,"grid":196,"attempts":302,"same_week":303,"maker_shows":274,"maker_hidden":331,"reader_version":332,"card":333},"8244815","Chan","pure C implementation of Go channels","title","Show HN: Chan – pure C implementation of Go channels","https:\u002F\u002Fgithub.com\u002Ftylertreat\u002Fchan","github.com","tylertreat",1409351642,2014,150,44,165,2272,8,"notable","languages","concurrency library","library",[24,25,26,27,28],"c channels","go channels","concurrency","pthread","coroutines","mixed",-0.094,{"positive":32,"neutral":33,"mixed":34,"critical":33},3,7,0,17,{"execution":37,"idea":38,"docs":39,"design":40},{"positive":34,"critical":33},{"positive":34,"critical":34},{"positive":34,"critical":34},{"positive":41,"critical":34},1,[41,34,41,34,34,41,41,41,32,34,34,34,34,34,32,34,34,34,34,34,32,34,32,34,34,34,34,32,34,41,41,34,32,34,34,34,34,43,43,43],5,null,{"problem":46,"audience":56,"pricing":44,"motivation":44,"time_to_build":44,"stack":67,"openness":83,"stage":84,"team_size":84},{"value":47,"source":48,"evidence":49},"Brings Go-style channels for thread communication to C","inferred",[50,52],{"id":51},"post",{"id":53,"by":54,"text":55},"8245122","srean","Quick question: isn't channel's raison d'etre the fact that they need not be backed by system threads, that they are considerably cheaper and one can fire tens of thousands of…",{"value":57,"source":48,"evidence":58},"C programmers wanting channel-based concurrency",[59,63],{"id":60,"by":61,"text":62},"8245083","chi42","Pretty nifty. I like the names of the functions chan_can_recv() and chan_can_send(). Made me think think of the old cooking show \"Yan Can Cook.\"",{"id":64,"by":65,"text":66},"8244935","vhost-","This is pretty awesome. I do a lot of Go and C and this just might come in handy. Thanks for sharing!",[68,76],{"value":69,"source":70,"evidence":71},"C","maker",[72,73],{"id":51},{"id":74,"by":11,"text":75},"8244928","Thanks, I'm not much of a C programmer, so I appreciate the feedback. I'm not sure what you're referring to with the mutexes and pcond not being on the struct because they are.…",{"value":77,"source":48,"evidence":78},"pthreads",[79],{"id":80,"by":81,"text":82},"8245011","copx","> #include \u003Cpthread.h> That is not \"pure C\". \"pthread.h\" (POSIX threads) is not part of the C language standard, it is a system-specific header commonly found on UNIX systems.…","open_source","unknown",{"praise":86,"objections":100,"requests":135,"questions":144,"alternatives":152},[87,96],{"value":88,"source":89,"evidence":90},"Nice, useful for C and Go programmers","commenter",[91,92],{"id":64,"by":65,"text":66},{"id":93,"by":94,"text":95},"8245041","WalterBright","Very nice. Any chance of Boost licensing it?",{"value":97,"source":89,"evidence":98},"Clever function naming",[99],{"id":60,"by":61,"text":62},[101,109,124],{"value":102,"source":89,"evidence":103},"Relies on pthreads, so not pure C",[104,105],{"id":80,"by":81,"text":82},{"id":106,"by":107,"text":108},"8245163","readerrrr","I agree, OP could have used the C11 feature, \u003Cthreads.h>",{"value":110,"source":89,"evidence":111},"Memory leaks and missing mutex\u002Fcond cleanup",[112,116,120],{"id":113,"by":114,"text":115},"8245015","pmahoney","The struct is currently storing a pointer to the mutex (which was allocated with malloc). The call to pthread_mutex_destroy does not free that memory. Valgrind is your friend :)…",{"id":117,"by":118,"text":119},"8245484","BrandonM","I think you need to add ``` pthread_cond_destroy(&chan->m_cond); ``` After https:\u002F\u002Fgithub.com\u002Ftylertreat\u002Fchan\u002Fblob\u002Fmaster\u002Fsrc\u002Fchan.c#L136",{"id":121,"by":122,"text":123},"8246076","clarry","You shouldn't allocate heap space for a pointer in blocking_pipe_read. Also, it looks like you're leaking it in the else branch. Just allocate a pointer on the stack, read into…",{"value":125,"source":89,"evidence":126},"Struct design: mutexes should be embedded, not malloc'd",[127,131],{"id":128,"by":129,"text":130},"8244898","eps","Good stuff, thanks for sharing. Random comments based on a quick glance through the code if I may. ``` chan_t* chan_init(int capacity); ``` should be \"size_t capacity\", since…",{"id":132,"by":133,"text":134},"8245006","millstone","What eps means is that, currently you have a pointer to a mutex in your struct: ``` struct chan_t { pthread_mutex_t* m_mu;... } ``` And initialize it like so: ```…",[136,140],{"value":137,"source":89,"evidence":138},"Use size_t for capacity",[139],{"id":128,"by":129,"text":130},{"value":141,"source":89,"evidence":142},"Boost-style licensing",[143],{"id":93,"by":94,"text":95},[145],{"value":146,"source":89,"evidence":147},"How does it compare to ZeroMQ inproc sockets?",[148],{"id":149,"by":150,"text":151},"8245508","SeoxyS","How does this compare to using ZeroMQ inproc sockets?",[153,160,171,178],{"value":154,"source":89,"evidence":155},"libtask by Russ Cox",[156],{"id":157,"by":158,"text":159},"8245076","kersny","Libtask[1] by Russ Cox (one of the creators of Go) may provide some inspiration. It implements channels but uses coroutines instead of threading. As a consequence it has some…",{"value":161,"source":89,"evidence":162},"Plan 9 thread library",[163,167],{"id":164,"by":165,"text":166},"8245509","arjovr","The circle is now complete... Plan 9 from user space implementation of channels. http:\u002F\u002Fswtch.com\u002Fusr\u002Flocal\u002Fplan9\u002Finclude\u002Fthread.h",{"id":168,"by":169,"text":170},"8245794","mseepgood","http:\u002F\u002Fplan9.bell-labs.com\u002Fmagic\u002Fman2html\u002F2\u002Fthread",{"value":172,"source":89,"evidence":173},"libco",[174],{"id":175,"by":176,"text":177},"8245997","byuu","Just a forewarning: that library, like most C cooperative threading libraries, is using ucontext. ucontext is unbearably slow, to the point where it's just as fast to use real…",{"value":179,"source":89,"evidence":180},"ZeroMQ inproc sockets",[181],{"id":149,"by":150,"text":151},{"comments":183,"answered":41,"key":184},4,[185,186,189],{"id":74,"text":75},{"id":187,"text":188},"8245028","Got it, that makes more sense.",{"id":190,"text":191},"8245132","I believe you're confusing goroutines with channels. Goroutines are lightweight threads of execution. Channels are the pipes that connect goroutines.",{"commenters":193,"max_depth":33,"maker_replies":183,"first_comment_mins":194,"lifespan_hours":195},30,23,56,[197,199,201,203,205,209,210,211,212,216,219,221,223,225,228,230,232,236,239,243,245,249,251,253,255,258,261,264,266,267,271,273,276,277,278,281,282,284,287,290,292,295,298,300],[128,34,41,198,129,34],"project\u002Fcritical\u002Fexecution",[74,34,34,200,11,41],"maker\u002Fneutral\u002Fexecution",[202,34,41,198,129,34],"8244994",[187,34,34,204,11,41],"maker\u002Fneutral\u002Fnone",[206,34,34,207,208,34],"8244998","commenter\u002Fneutral\u002Fexecution","sdab",[132,34,41,198,133,34],[113,34,41,198,114,34],[121,34,41,198,122,34],[213,34,32,214,215,34],"8245443","project\u002Fneutral\u002Fexecution","DSMan195276",[217,34,34,207,218,34],"8245604","yew",[220,34,34,207,215,34],"8245637",[222,34,34,207,218,34],"8245710",[224,34,34,207,129,34],"8245808",[226,34,34,227,218,34],"8245837","commenter\u002Fneutral\u002Fnone",[229,34,34,207,129,34],"8245761",[157,41,32,231,158,34],"project\u002Fneutral\u002Fidea",[233,41,34,234,235,34],"8245652","other\u002Fneutral\u002Fnone","rubiquity",[237,41,34,238,235,34],"8247954","commenter\u002Fneutral\u002Fdocs",[240,41,34,241,242,34],"8245727","other\u002Fneutral\u002Fidea","baruch",[175,41,34,244,176,34],"other\u002Fcritical\u002Fperformance",[246,41,34,247,248,34],"8250740","commenter\u002Fneutral\u002Fperformance","ezy",[250,41,34,247,176,34],"8251705",[53,252,32,231,54,34],2,[190,252,34,254,11,41],"commenter\u002Fneutral\u002Fidea",[256,252,32,231,257,34],"8245165","chc",[259,32,34,241,260,34],"8245618","edsiper2",[262,32,34,241,263,34],"8246102","sircomatose",[265,32,34,227,260,34],"8246481",[164,183,34,241,165,34],[268,43,32,269,270,34],"8245485","project\u002Fneutral\u002Fdocs","Rapzid",[272,43,34,204,11,41],"8245515",[168,274,34,275,169,34],6,"other\u002Fneutral\u002Fdocs",[117,33,41,198,118,34],[80,18,41,198,81,34],[279,18,34,207,280,34],"8245106","mappu",[106,18,32,214,107,34],[283,18,34,207,215,34],"8245474",[285,18,34,234,286,34],"8245949","justincormack",[288,18,34,234,289,34],"8246243","jevinskie",[291,18,34,234,107,34],"8246332",[60,293,43,294,61,34],9,"project\u002Fpositive\u002Fdesign",[93,296,43,297,94,34],10,"project\u002Fpositive\u002Fnone",[64,299,43,297,65,34],11,[149,301,32,231,150,34],12,[],[304,309,314,318,322,326],{"id":305,"name":306,"points":307,"category":308},"8246218","tmux-resurrect",241,"dev_tools",{"id":310,"name":311,"points":312,"category":313},"8258132","RandomStartup.org",119,"web_saas",{"id":315,"name":316,"points":317,"category":20},"8239113","luajit-libuv",101,{"id":319,"name":320,"points":321,"category":308},"8237111","Impulse",93,{"id":323,"name":324,"points":325,"category":308},"8241978","Howm",71,{"id":327,"name":328,"points":329,"category":330},"8237176","SuperTrip",69,"games",false,"v2",{"id":334,"name":5,"line":6,"ai":331,"cat":20,"year":13,"points":14,"comments":15,"rec":29,"s":335,"top":18,"kw":336,"maker":11,"domain":10,"tier":19,"attempts":34,"strip":337,"url":9,"mix":338,"praise":88,"objection":102,"sub":21},8244815,-0.09,[24,25,26,27,28],"1010011130000030000030300003011030000555",[32,33,34,33],1794036522143]