CS 343 - Concurrent and Parallel Programming

Code Examples

Makefile

The following examples require GNU make, which is make on Linux.

String to Integer

The C++ stoi routine does not handle an erroneous string of the form "123ABC" correctly, returning a valid integer result instead of raising an invalid_argument exception. The μC++ convert routine:

intmax_t convert( const char * str );

correctly handles erroneous string-to-integer conversions.

#include <iostream>
#include <string>
using namespace std;

int main() {
	try {
		intmax_t i = convert( "123" );
		cout << i << endl;
		i = convert( "123ABC" );
		cout << i << endl;
	} catch( invalid_argument ) {
		cout << "invalid integer" << endl;
	}
}

123
invalid integer

The convert routine correctly handles string-to-integer conversions and is directly accessible in μC++ programs, but must be copied into C++ programs.

C++

μC++

C∀

Barging Checker

The following macros are used to check for barging with locks/monitors that allow calling and signalled tasks to compete for the lock.