<?xml version="1.0" encoding="utf-8"?>
<oembed>
  <version>1</version>
  <type>rich</type>
  <provider_name>Libsyn</provider_name>
  <provider_url>https://www.libsyn.com</provider_url>
  <height>90</height>
  <width>600</width>
  <title>episode 34: Rust, coroutines and cohosting</title>
  <description>Finally, the &amp;quot;we&amp;quot; in announcements doesn't just mean the royal we / majestic plural, but there's an actual co-host! Introduction is in the audio contents, so I guess you'll just have to listen. &amp;amp;lt;/clickbait&amp;amp;gt; We talk about first contact with the Rust programming language, coroutines for implementing lightweight tasks/threads, various smaller topics and some upcoming events.&amp;amp;nbsp; Links:  Rust programming language:  Discover the world of microcontrollers through Rust! The Embedded Rust Book LLVM Intermediate representation   Coroutines / protothreads:  Coroutines&amp;amp;nbsp;and simpler&amp;amp;nbsp;protothreads&amp;amp;nbsp;for building stackless cooperative tasks Protothreads under the hood:&amp;amp;nbsp;Duff's device&amp;amp;nbsp;or&amp;amp;nbsp;GCC's computed goto  convoluted example: 6502 asm + Tcl = protothreads   short video of&amp;amp;nbsp;VGA generator board in action RetroChallenge 2019/03&amp;amp;nbsp;(whole month of March) is open Maker Faire Ruhr&amp;amp;nbsp;(DASA, Dortmund, DE): 23+24&amp;amp;nbsp;March HCC!retro meeting&amp;amp;nbsp;(Bilthoven, NL): 16&amp;amp;nbsp;March  Here's a code snippet hopefully illustrating what I called &amp;quot;coroutines&amp;quot; and should probably have been called &amp;quot;protothreads&amp;quot;. Function &amp;quot;print_2nd_word&amp;quot; is a protothread. It can be called repeatedly passing a character each time. Only the 2nd word is printed, one character at a time.       void print_2nd_word( char c )    {        CR_BEGIN;                    while ( c != ' ' )           CR_YIELD;           CR_YIELD; // skip space           while ( c != ' ' ) {            putchar( c );            CR_YIELD;        }    }   To do this, the function keeps track of where it exited last time it was called, using a number of macros:       #define CR_BEGIN static void *jmp = &amp;amp;amp;&amp;amp;amp;lbl_crstart; goto *jmp; lbl_crstart: ( void )jmp;    #define CR_YIELD do { jmp = &amp;amp;amp;&amp;amp;amp;GLUE( lbl, __LINE__ ); return; GLUE( lbl, __LINE__ ): ( void )jmp; } while ( 0 )   &amp;quot;CR_BEGIN&amp;quot; is basically setup-code. &amp;quot;CR_YIELD&amp;quot; is the simplest primitive in this context, and does: exit the protothread function, and resume at this point next time it's called. More advanced macros - e.g. to repeatedly wait for an event - can be built on top of, or in the same way as &amp;quot;CR_YIELD&amp;quot;. Note that these macros use GCC's &amp;quot;computed gotos&amp;quot; (i.e. take the address of a C label, and jump to that address using &amp;quot;goto&amp;quot;). Here's an implementation of both macros using ANSI C:       #define CR_BEGIN static int cr_st = 0; switch( cr_st ) { case 0: ;    #define CR_YIELD do { cr_st = __LINE__; return; case __LINE__: ; } while( 0 )    #define CR_END CR_YIELD; }   (In this case, an additional macro &amp;quot;CR_END&amp;quot; is necessary as glue to conform to C syntax/nesting.) &amp;amp;nbsp; Funfact: it's a bit of a PITA to add sourcecode to this page. </description>
  <author_name>CBA Podcast</author_name>
  <author_url>http://podcast.cba.si</author_url>
  <html>&lt;iframe title="Libsyn Player" style="border: none" src="//html5-player.libsyn.com/embed/episode/id/8624468/height/90/theme/custom/thumbnail/yes/direction/forward/render-playlist/no/custom-color/88AA3C/" height="90" width="600" scrolling="no"  allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen&gt;&lt;/iframe&gt;</html>
  <thumbnail_url>https://assets.libsyn.com/secure/item/8624468</thumbnail_url>
</oembed>
