A thread ends in one of three ways: natural causes, an early exit, or sudden death. Yes, it’s exciting, but no more than any aspect of programming.
Continue reading
Author Archives: dgookin
Leaving a Thread Early
Threads in your code go off and do their own thing, running independently from other parts of the code. Still, the thread is established as a function in your source code file. Like any function, it can leave early.
Continue reading
The Elevator Ride – Solution
To code a simulated elevator ride you must know the floor requests, up and down. This is the challenge given for this month’s Exercise, which can either drive you nuts or delight you depending on how you craft your solution.
Continue reading
Multiple Thread Mania
In last week’s Lesson, a program spawned a single thread. This thread runs at the same time as the main program, interrupting text input (if you let it). Such fun! But a multithreaded program isn’t limited to running just two threads. Your code can spawn multiple threads, each running simultaneously.
Continue reading
The Elevator Ride
Difficulty: ★ ★ ★ ☆
I recently stayed at a resort with a tall hotel tower, over 30 stories. As I rode the elevator up to my floor, I thought about how the lift worked like a pointer traversing an array: The floors are elements. Each stop going up represents a passenger’s desired destination, as do stops on the return trip. My programmer brain was on fire!
Continue reading
Here a Thread, There a Thread
Better than forking — especially grandchild forking — is to use threads. These program chunks are more manageable than forking and they don’t recreate the entire program (process). Still, threads aren’t without their quirks. Further, they’re available only to the POSIX standard. Sorry, Windows.
Continue reading
Forking the Grandchildren
I wrote about forking a while back, in June 2015. The fork splits a program into two processes, each capable of handling different tasks simultaneously. The power behind this trick is the fork() function.
Continue reading
From Decimal Value to a String
The challenge for this month’s Exercise is to split a decimal value into its integer and fractional portions. But what if you need the fractional portion as a string?
Continue reading
Splitting a Decimal Value – Solution
Cleaving a decimal value into its integer and fractional portions is a neat trick, one that relies upon C natural capability to thwack off the decimal portion of a float when it’s recast as an integer. Knowing about this conversion makes solving this month’s Exercise a whole lot easier.
Continue reading
Conditional Expressions Used as Values
It was weird when I first saw it: A conditional expression used to determine a value. It sounds odd, but it works.
Continue reading