{"id":4844,"date":"2013-10-31T05:15:58","date_gmt":"2013-10-30T18:15:58","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4844"},"modified":"2016-02-08T19:48:16","modified_gmt":"2016-02-08T09:48:16","slug":"codeblocks-d-thread-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/codeblocks-d-thread-tutorial\/","title":{"rendered":"Code::Blocks D Thread Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/D\/Thread\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Code::Blocks D Thread Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/D\/Thread\/CodeBlocks_D_SendReceive_Primer-61of.jpg\" title=\"Code::Blocks D Thread Tutorial\" \/><\/a><p class=\"wp-caption-text\">Code::Blocks D Thread Tutorial<\/p><\/div>\n<p>The tutorial today is about a programming IDE called Code::Blocks, and it builds on <a href='#cbidpt' title='Code::Blocks IDE D Primer Tutorial'>Code::Blocks IDE D Primer Tutorial<\/a>.   For the tutorial today we are going to write a D program that <a target=_blank title='std.concurrency' href='http:\/\/dlang.org\/phobos\/std_concurrency.html'>spawns a thread<\/a> and communicates with messages to and from that thread, the coding for which uses <a target=_blank title='D delegates ++' href='http:\/\/www.freshsources.com\/page1\/page7\/files\/D-2.pdf'>delegate<\/a> functionality.<\/p>\n<p>Code::Blocks can be an IDE for much more than D &#8230; it can supervise Matlab, Fortran, ARM, AVR, Direct\/X, FLTK, GLFW, GLUT, GTK+, Irrlicht, Lightfeather, MCS51, Ogre, OpenGL, PowerPC, QT4, SDL, SFML, STL port, SmartWin, TriCore and wxWidgets projects.   In coming days and weeks we&#8217;ll look at more.<\/p>\n<p>In today&#8217;s <a target=_blank title='click on picture' href=\"http:\/\/www.rjmprogramming.com.au\/C\/D\/Thread\/\">tutorial<\/a> we write a simple D program using a thread, and communicate with that thread with messages.   We <a target=_blank title='Semantic Satiation' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=899'>really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really<\/a> hope you enjoy it.<\/p>\n<p>Link to Code::Blocks &#8220;spiritual home&#8221; download page at <a target=_blank title='Code::Blocks download page' href='http:\/\/www.codeblocks.org\/downloads'>Code::Blocks<\/a>.<\/p>\n<p>Link to D information &#8230; <a target=_blank title='D' href=\"http:\/\/en.wikipedia.org\/wiki\/D_(programming_language)\u200e\">from Wikipedia<\/a> &#8230; source of idea for the tutorial &#8230; merci.<br \/>\nLink to Digital Mars D download page &#8230; <a target=_blank title='Digital Mars' href='http:\/\/dlang.org\/download.html'>here<\/a>.<br \/>\nLink to some downloadable D code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/C\/D\/Thread\/SendReceive.d_GETME' title='SendReceive.d'>SendReceive.d<\/a>\n<\/p>\n<hr \/>\n<p id='cbidpt'>Previous <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4601\">Code::Blocks IDE D Primer Tutorial<\/a> of interest is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/CodeBlocks\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Code::Blocks IDE D Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/CodeBlocks\/CodeBlocks_Primer-28of.jpg\" title=\"Code::Blocks IDE D Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Code::Blocks IDE D Primer Tutorial<\/p><\/div>\n<p>The tutorial today is about a programming IDE called Code::Blocks, and it builds on yesterday&#8217;s <a target=_blank href=\"#dpt\">D Primer Tutorial<\/a> as shown below.<\/p>\n<p>Programming <a target=_blank title='IDE information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/IDE\u200e'>IDE<\/a>s take a lot of the hard work out of tasks such as compiling and linking in languages such as D, Matlab, Fortran (Code::Blocks) or Java, C, C++, VB.Net and C# (NetBeans) &#8230; and please know that there are many other languages and many other IDEs.   In the case of Code::Blocks IDE, which this blog introduces to you today (its customary to shake hands, and no <a target=_blank title='pardon?' href='http:\/\/www.youtube.com\/watch?v=SGZV6fsotYo'>Klingon<\/a> is necessary), it can create a D code project environment.   To cut a long story short, there aint nothin&#8217; wrong with a good ol&#8217; IDE, but beware of IDEs in <a target=_blank title='Ides of March' href='https:\/\/www.youtube.com\/watch?v=Je0gTnheVe4'>March<\/a>.<\/p>\n<p>In saying that about IDEs, and how they make programming easier, often with Open Source programming, it is advantageous to know what goes on &#8220;under the hood&#8221; (or even &#8220;in the &#8216;hood&#8221; &#8230; chortle, chortle).   <span id='makefile'>So if you ever get an opportunity to get helped creating your own makefile<\/span> (or make it yourself, even with the <a target=_blank title='Sweet Green Icing' href='http:\/\/www.youtube.com\/watch?v=CPMpeNDIGdk'>Sweet Green Icing<\/a> &#8230; knew it could be worked in!) for something, take the opportunity to learn how to do this, as the Open Source world will become a little easier to navigate with such types of knowledge.   You&#8217;ve got to admire those early designers of computer languages, and those days when all you had was this tiny bit of memory (<a target=_blank title='64k' href='http:\/\/www.crashonline.org.uk\/39\/z88.htm'>64k<\/a> or <a target=_blank title='Voyager computer system' href='http:\/\/www.activeastronomy.org\/Home\/daniel'>&#8220;into the heliosphere on 8,000 bytes of memory&#8221;<\/a>) to play with to create your program.   <\/p>\n<p>In today&#8217;s <a target=_blank title='click on picture' href=\"http:\/\/www.rjmprogramming.com.au\/CodeBlocks\/\">tutorial<\/a> we write a simple D program based on  <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/C\/D\/idea.d_GETME' title='idea.d'>idea.d<\/a> of yesterday, to do with a MovingAverage program, with some simple struct and class bits added on, all under the supervision of Code::Blocks IDE.<\/p>\n<p>Code::Blocks can be an IDE for much more than D &#8230; it can supervise Matlab, Fortran, ARM, AVR, Direct\/X, FLTK, GLFW, GLUT, GTK+, Irrlicht, Lightfeather, MCS51, Ogre, OpenGL, PowerPC, QT4, SDL, SFML, STL port, SmartWin, TriCore and wxWidgets projects.   In coming days and weeks we&#8217;ll look at more.<\/p>\n<p>So with the <a target=_blank title='D in Code::Blocks' href=\"http:\/\/www.rjmprogramming.com.au\/CodeBlocks\/\">tutorial<\/a> today we don&#8217;t do Hello World exactly, but it is pretty simple code to give a moving average of record (lengths) entered at the keyboard interactively, and show a rudimentary struct and class usage.   By the way, if this had been written in C as hello.c and put into the right place, the compilation of this into a Digital Mars C program would have been as simple as &#8230; dmc hello.c &#8230; (and then &#8230; hello &#8230; to run &#8230; cute (and easy), huh?)<\/p>\n<p>Link to Code::Blocks &#8220;spiritual home&#8221; download page at <a target=_blank title='Code::Blocks download page' href='http:\/\/www.codeblocks.org\/downloads'>Code::Blocks<\/a>.<\/p>\n<p>Link to D information &#8230; <a target=_blank title='D' href=\"http:\/\/en.wikipedia.org\/wiki\/D_(programming_language)\u200e\">from Wikipedia<\/a> &#8230; source of quote above.<br \/>\nLink to Digital Mars D download page &#8230; <a target=_blank title='Digital Mars' href='http:\/\/dlang.org\/download.html'>here<\/a>.<br \/>\nLink to some downloadable D code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/CodeBlocks\/hello.d_GETME' title='hello.d'>hello.d<\/a>\n<\/p>\n<hr \/>\n<p id='dpt'>Previous <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4586\">D Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/D\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"D Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/D\/D_DigitalMars_CodeBlocks_Primer-9of.jpg\" title=\"D Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">D Primer Tutorial<\/p><\/div>\n<p>Yes, there is a D &#8230; D comes after C &#8230; and that pans out to be true &#8230; but what if we find life on Mars &#8230; you heard it here.<\/p>\n<p id='hfafodm'>Have been a fan of what Digital Mars do for a while, because if you are interested in programming languages you don&#8217;t want to interfere with various IDE programming language compilation arrangements, and the GCC\/Xcode relationship, for example, is quite complex, and you probably don&#8217;t want to push its functionality in wrong directions, or you could break your environment &#8230; and we all know <a target=_blank title='breaking up' href='http:\/\/www.youtube.com\/watch?v=tbad22CKlB4'><i>breaking up is hard to do<\/i><\/a>.<\/p>\n<p>Digital Mars C is like an independent voice (but in saying that, tomorrow&#8217;s tutorial shows it integrated into Code::Blocks IDE) and have been using it successfully on Windows for quite some time, especially for quick one off programs that need doing &#8230; though the &#8220;toast at breakfast even if you don&#8217;t want it&#8221; algorithm still needs work.<\/p>\n<p>Am selling Digital Mars short to just stop at that.   Take a look at the language D (it comes after C), and yes, with Digital Mars arrangements, please first install C (didn&#8217;t show you this with install, but &#8220;just do the Nike&#8221; on it).<\/p>\n<p>Let&#8217;s look at Wikipedia view of D &#8230; will make it that it comes after C<\/p>\n<blockquote><p>The D programming language is an object-oriented, imperative, multi-paradigm system programming language created by Walter Bright of Digital Mars. Though it originated as a re-engineering of C++, D is a distinct language, having redesigned some core C++ features while also taking inspiration from other languages, notably Java, Python, Ruby, C#, and Eiffel.<\/p>\n<p>D&#8217;s design goals attempt to combine the performance of compiled languages with the safety and expressive power of modern dynamic languages. Idiomatic D code is commonly as fast as equivalent C++ code, while being shorter and memory-safe. [7]<\/p>\n<p>Type inference, automatic memory management and syntactic sugar for common types allow faster development, while bounds checking, design by contract features and a concurrency-aware type system help reduce the occurrence of bugs.[8]<\/p><\/blockquote>\n<p> &#8230; chortle &#8230; chortle<\/p>\n<p>So with the <a target=_blank title='D' href=\"http:\/\/www.rjmprogramming.com.au\/C\/D\/\">tutorial<\/a> today we don&#8217;t do Hello World exactly, but it is pretty simple code to give a moving average of record (lengths) entered at the keyboard interactively.   By the way, if this had been written in C as idea.c and put into the right place , the compilation of this into a Digital Mars C program would have been as simple as &#8230; dmc idea.c &#8230; (and then &#8230; idea &#8230; to run &#8230; cute (and easy), huh?)<\/p>\n<p>Link to D information &#8230; <a target=_blank title='D' href=\"http:\/\/en.wikipedia.org\/wiki\/D_(programming_language)\u200e\">from Wikipedia<\/a> &#8230; source of quote above.<br \/>\nLink to Digital Mars D download page &#8230; <a target=_blank title='Digital Mars' href='http:\/\/dlang.org\/download.html'>here<\/a>.<br \/>\nLink to some downloadable D code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/C\/D\/idea.d_GETME' title='idea.d'>idea.d<\/a>\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4586' onclick='var dv=document.getElementById(\"d4586\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4586' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4601' onclick='var dv=document.getElementById(\"d4601\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4601' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4844' onclick='var dv=document.getElementById(\"d4844\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4844' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The tutorial today is about a programming IDE called Code::Blocks, and it builds on Code::Blocks IDE D Primer Tutorial. For the tutorial today we are going to write a D program that spawns a thread and communicates with messages to &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/codeblocks-d-thread-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,12,37],"tags":[220,287,331,775,1510,997,1177,1270,1319],"class_list":["post-4844","post","type-post","status-publish","format-standard","hentry","category-codeblocks","category-elearning","category-tutorials","tag-codeblocks","tag-d","tag-digital-mars","tag-messaging","tag-oct3","tag-programming","tag-spawn","tag-thread","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/4844"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=4844"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/4844\/revisions"}],"predecessor-version":[{"id":20061,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/4844\/revisions\/20061"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=4844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=4844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=4844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}