<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Thread on Lloyd Rochester's Geek Blog</title><link>https://lloydroc.github.io/tags/thread/</link><description>Recent content in Thread on Lloyd Rochester's Geek Blog</description><generator>Hugo</generator><language>en</language><copyright>Copyright © 2025, Lloyd Rochester.</copyright><lastBuildDate>Mon, 12 Aug 2019 14:30:06 +0000</lastBuildDate><atom:link href="https://lloydroc.github.io/tags/thread/index.xml" rel="self" type="application/rss+xml"/><item><title>pthread barrier example</title><link>https://lloydroc.github.io/post/c/pthread-barrier-example/</link><pubDate>Mon, 12 Aug 2019 14:30:06 +0000</pubDate><guid>https://lloydroc.github.io/post/c/pthread-barrier-example/</guid><description>&lt;p>A Barrier in computing is a synchronization method where a group of threads cannot proceed until a condition allows the blocked threads to proceed. In this post we will construct an example of a Barrier that relates to men and women at the dinner table using pthreads. We will men waiting to get their food, but the men will be blocked until the woman has eaten, thus, trigger the start state of the Barrier. Ladies First!&lt;/p></description></item><item><title>Java Cyclic Barrier</title><link>https://lloydroc.github.io/post/java/cyclic-barrier/</link><pubDate>Mon, 25 Feb 2019 08:00:00 +0000</pubDate><guid>https://lloydroc.github.io/post/java/cyclic-barrier/</guid><description>&lt;h1 id="hahahugoshortcode76s0hbhb">Java Cyclic Barrier&lt;/h1>
&lt;p>Imagine a scenario where you have N threads and can only do something when M of them are ready. Java already has this built in since 1.5 with the &lt;a href="https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/CyclicBarrier.html#await(long,java.util.concurrent.TimeUnit)">CyclicBarrier&lt;/a>.&lt;/p>
&lt;p>From the Javadoc we see the CyclicBarrier is &lt;em>A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. CyclicBarriers are useful in programs involving a fixed sized party of threads that must occasionally wait for each other. The barrier is called cyclic because it can be re-used after the waiting threads are released.&lt;/em>&lt;/p></description></item><item><title>Java Multicore Example</title><link>https://lloydroc.github.io/post/java/multicore/</link><pubDate>Sun, 24 Feb 2019 14:57:00 +0000</pubDate><guid>https://lloydroc.github.io/post/java/multicore/</guid><description>&lt;h1 id="hahahugoshortcode75s0hbhb">Java Multicore Example&lt;/h1>
&lt;p>Any program these days that does any significant computational load should utilize the available processor cores. In this post we&amp;rsquo;ll show an example using Java where we schedule &lt;a href="https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/Callable.html">Callables&lt;/a> on all available processor cores. In Java a Callable is task that returns a result and may throw an exception. It is very similar to a &lt;a href="https://docs.oracle.com/javase/10/docs/api/java/lang/Thread.html">Thread&lt;/a>, but gives a much easier way to return the result asynchronous computation. I typically don&amp;rsquo;t see many reasons to not use Callables over Threads, since even if you don&amp;rsquo;t want or need to return the result you can still return some sort of status code. This blurb is directly from the Javadoc &lt;em>The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.&lt;/em>&lt;/p></description></item></channel></rss>