Tech posts by aclassifier
Also see Designer's note page

You are at
Archive by month and about me: here
Last edit: 4Sept2015
Started move: September 2012
All updates at, but the overview is updated

Tuesday, December 27, 2011

036 - WYSIWYG semantics

This blog note has been moved to on 17Jan2014

Saturday, December 3, 2011

034 - Output guard vs. "channel ready" channel

Last edit: 16. August 2012
On the airplane home, the other day, I came upon an idea that I thought would make life easier. When I told a guy at work, he said, "oh, it's already in Linux".

I assume that you're somewhat familiar with "channels". In this respect I was raised with the occam language. (You would find Wikipedia-articles for most of the names I'll throw here. So I won't get too deep into some details.)

Here, a channel is based on CSP (later), and it is one-directional, non-buffered and blocking. It's even one-to-one. It connects tight processes to each other. It also allows threads to be equally tight. So, the first process that comes to a channel (be it sender or receiver), must be descheduled and not ever run again before the second process arrives on the channel. At that time there's a memcpy of the correct data from the sender's private context, to the receiver's matching field. It is possible to make it type safe. The message is passed across, while both sender and receiver are still. In Ada it's called a rendezvous. In Go it has no name. When the memcpy is done, usually the second on the channel just runs on, while the first is put in the ready-to-be-scheduled queue.

There is a mechanism called on ALT or a "select", where a process may wait for a number of (input) channels. A channel may be with data, without data, or timeouts. In my world (opposite to Linux select), there is exactly one cause that may trigger the SELECT. I will use capitalized "SELECT" here to cover any such idiom, to differentiate from the Linux "select". The first cause that triggers the SELECT will be stored and cause a later rescheduling, but any potential causes that "lost", will not be allowed to cause an additional triggering. Only one cause per scheduling of a process. Very different from Linux select.

Said differently: the SELECT will put all the channels in the set to "first was here". When the first "second" contender on a channel in the set arrives, all the "first" attributes are removed from the rest of the set. This is a beautiful algorithm, that I think was first implemented in microcode on the first transputer processer in 1984. Inmos in Bristol, UK, made it, and David May and Tony Hoare (the father of CSP, "Communicating Sequential Processes" process algebra) were the main architects. The transputer basically was a machine designed to run the subset of CSP that was called occam. It's 28 years ago. Ada based its concurrency model on CSP. And 26 years after occam, Google designed the Go programming language, which also has based its concurrency model on CSP, just like the same guys had done at Lucent some 10 years before with their Limbo language. Except, at that time they didn't state the roots of their "chan of protocol". And transputer designer David May now is active with a company called XMOS, and a language called XC, based on the same ideas. So, CSP-based concurrency seems to be increasingly coming.

With this scheme communication equals synchronization.

In CSP they talk about "choice". It may be deterministic or "external" or nondeterministic or "internal" (often written as [] and |~|).

The SELECT is for the teacher who assigns work to his students. He then falls to sleep (or does other things) and is awaked when the first student is finished. The student is then served, and the SELECT is entered again. The new set may include the first student, when some fair scheme is used to avoid him spam the teacher. Or the SELECT may be non-deterministic. Read in the literature, f.ex. the Promela Wiki-article (more below).

With this scheme, the teacher may say that one of the students is not allowed to deliver his result before after two hours. So, there may be timers in the SELECT set. This would also make busy polling possible, should this be needed at the application level. But the run-time scheduler NEVER needs busy-polling. Another way to say this is that a process always has a cause when it's scheduled. Just think about Java's notify and notifyall, which may schedule a process for no reason!

Also, there may be an INPUT GUARD for each channel (applied to our special student for two hours). This is usually implemented as a conditional to each member of the SELECT set. Think of the SELECT GUARD set as a bit-mask, one bit per element in the set, just like in Linux select.

Now I'm getting closer to the theme of this note: Output guard vs. "channel ready" channel.

Some times it's required to buffer a message on a channel. In occam we used to do this by inserting a single buffer process, or a couple of processes to make one composite process called an "overflow buffer", which made it possible to detect a too eager producer and associated too slow consumer - at this application level. One time I needed a buffer of a hundred buffer positions, and I just started 100 buffers. Easy! The downside was that there would be 101 memory copies, so most often a ring buffer was administered inside the first of the two processes in the composite overflow buffer process.

The alternative could be for the eager producer (it has no idea itself how eager it is) to have something called an OUTPUT GUARD available. If you want to see it, have a look at the Promela process meta language (Wikipedia). This way, both inputs and outputs may be collected in the SELECT. So, having just one channel, plus an "else", then the potential receiver, if it is able to receive, will inform through the output guard if it's ok to send. If not, the else will be taken. The SELECT with both input and output looks like the Linux select, but that one doesn't have the synchronized mechanism in the bottom.

There is a code examples in [6] (here, search for bufchansched).

It's a nice mechanism. I have never had it in my world. It was not implemented on the transputer, since it was a multi-core programming language. And implementing it across a network (links) presumably was not worth it. There was another mechanism to get the same functionality. If you know what mechanism, please comment.

An output guard mechanism is good for detecting a broken line. To detected a connected line, there would have to be polling. Busy polling is most often necessary for this (assuming no hw edge interrupt). But the output guard seems not so relevant to handle the fast producer, slow consumer scenario - between internal processes. The same broken / connected scenario also would go for detecting that the other process has stopped, for some reason. Perhaps enough for a new blog note here.

So, here's the solution, to avoid the output guard, to avoid busy polling. The solution that also almost exists in Linux.

A standard channel has zero buffers. Have a look at Promela and Go. They both support buffered channels. So, why not add them to [1]? What should happen when such a channel is full? The channel send just returns a flag saying that it’s full, and the channel would not block in that situation. Observe that blocking is perfectly ok and does not impact what a system is able to do. With enough "parallel slackness" to get all the I/O going at required speed, having a process block (waiting in a non-busy way, for the second to arrive at the channel). But for a driver, close to the "asynchronous world" it's nice not to block to get rid of incoming messages. And it's nice not to send it into an asynchronous message system that may plainly overflow, crash and restart. We need a better system. We need the driver process to not block in that situation and itself handle overflows.

So, in the suggestion, after the return of the buffer full flag, the process knows this and if any incoming message arrives from the external asynchronous world, it may set a hold line, send a hold message or throw away the message - or whatever it decides to. It's up to the process.

In this state, the process will SELECT around a timeout channel and this channel that's triggered by the run-time system, that arrives when there is room in the channel. The receiver has picked out one message or all, that semantics is not so important here.

When this "channel ready" channel fires, the process can send off the last message, which may also be tagged with an overflow bit, on the channel. And it's guaranteed to succeed (unlike in Linux).

I was rather satisfied by inventing this on the plane home. I didn't like that it was already in Linux write and select. I have tried to describe some of the dissimilarities. See [2] for write, EAGAIN or EWOULDBLOCK and [3] for select (or pselect) and fd_set *writefds. It's in the context of writing to a Linux pipe.

But please, could anyone help me with describing how my solution is much "thread safer" than Linux? I need more than this:

I have more of a language, since I would do as described and reasoned above. Linux calls and Linux processes and threads are not understood by C or C++. Up to C++11 at least. And only so much understood by Linux. A C++ library for Linux needed several mutexes and semaphors to implement an ALT/SELECT in the CSP context [4]. So, are write and select usages in Linux really thread safe? I have a scheduler that is driven by the channels, and it's not preemptive. And why do Linux programmers brag that they "program single-threaded"? Is it an indication that the Linux process model is too coarse or difficult or expensive? So that they haven't learned to decompose into processes, when there is state or roles to hide away into a separate process? After object-orientation or OO, it's time for process-orientation as an additional idiom.

Should have been fun to set up a comparison table of the CSP type SELECT with channel ready channel and the similar Linux solution. Even if they are both fruits, I fear that one is apple and the other bananas?
A Linux pipe vs. channel trait
Observe that a Linux pipe is byte-wise. You send so many bytes and then so many bytes, and they are concatenated in the pipe. There has to be a common view of how to pick out each message or token.

This implies that you could read past a token, since a sender may have to break up a message into several chunks. There is no foldback, you cannot push anything back again. So, the receiver has to keep track of these things.

A channel is message based. A full message per chunk. Finito.
Common usage of Linux select
A collegue told me that the common usage of a Linux select is to remove active polling for events from remote machines from the application level, in say a http server (router). He said that he always used select to wait for events on already open sockets. One socket per bit in the select bit map.

Internally between threads he never had used select.

And he rarely used ip addresses internally between processes, so no select there either.
"My idea" - again
I found an interesting sentence in [5]. Here is its process-oriented specification of a buffer: If a buffer is empty it must be ready for input. If it contains some messages, then the buffer must be ready to output the next message required. It is also possible that it will accept further input, but it does not have to. (my comment: is this buffer full?) But here is the interesting sentence: "If further events are to be possible (such as a channel which can report on whether or not the channel is empty), then...". This is "my" channel! I am even more convinced now, that "my" idea was quite good!
Epilogue: "The XCHAN paper"
During June and July 2012 I had the opportunity to channel this blog note into a full blown paper for the CPA-2012 (at University of Abertay Dundee, Scotland 26-29 August 2012). I have published for the WoTUG and CPA series conferences several times before, but this time it was especially exciting. See [8] and here:

XCHANs: Notes on a New Channel Type
Øyvind TEIG, Autronica Fire and Security AS, Trondheim, Norway

Abstract. This paper proposes a new channel type, XCHAN, for communicating messages between a sender and receiver. Sending on an XCHAN is asynchronous, with the sending process informed as to its success. XCHANs may be buffered, in which case a successful send means the message has got into the buffer. A successful send to an unbuffered XCHAN means the receiving process has the message. In either case, a failed send means the message has been discarded. If sending on an XCHAN fails, a built-in feedback channel (the x-channel, which has conventional channel semantics) will signal to the sender when the channel is ready for input (i.e., the next send will succeed). This x-channel may be used in a select or ALT by the sender side (only input guards are needed), so that the sender may passively wait for this notification whilst servicing other events. When the x-channel signal is taken, the sender should send as soon as possible -- but it is free to send something other than the message originally attempted (e.g. some freshly arrived data). The paper compares the use of XCHAN with the use of output guards in select/ALT statements. XCHAN usage should follow a design pattern, which is also described. Since the XCHAN never blocks, its use contributes towards deadlock- avoidance. The XCHAN offers one solution to the problem of overflow handling associated with a fast producer and slow consumer in message passing systems. The claim is that availability of XCHANs for channel based systems gives the designer and programmer another means to simplify and increase quality.

[1] -
"New ALT for Application Timers and Synchronisation Point Scheduling"
Øyvind Teig and Per Johan Vannebo
Communicating Process Architectures 2009 (CPA-2009)
Peter H. Welch et. al. (Eds.)
IOS Press, 2009, ISBN 978-1-60750-065-0

[2] -

[3] -

[4] - Search for "C++CSP2"

[5] - Concurrent and real-time systems. The CSP approach. Steve Schneider. Wiley, 2000. Page 210, example about buffers (7.4.1).

[6] - Lecture at NTNU, Trondheim in April 2012: - search for "bufchansched", since it's in Norwegian

[7] - Communicating Process Architectures 2012 (CPA-2012): Full programme:

[8] - "XCHANs: Notes on a New Channel Type"
Øyvind Teig
Communicating Process Architectures 2012.
Peter H. Welch et. al.(Eds.).
ISBN (later)

Monday, September 26, 2011

030 - Burning an mp3 music CD from iTunes

First written 22.Aug.2011, updated 24.Aug.11. iTunes 10.4, Mac OS Snow Leopard 10.6.8.

Two entries for some songs, and a repair action

First:  The normal no-fuzz procedure is described at

I burnt an mp3 music CD the other day. Since some of the songs were not in mp3 format, I had to manually convert them to mp3 before I burnt the playlist. And I had to export the playlist to a file and then edit it in a text editor to replace all occurances of .m4a with .mp3. Then I had to import the playlist-file again. Only then did iTunes obey my wish to burn only .mp3 files, and not complain that "81 songs", sorry, could not be burnt.

When I afterwards looked at one of the original CDs in the Music folder, it had two entries for each song: one m4a and one mp3, or one mp3 and another list entry also as mp3! And playing that album, every song was played twice.

I then used Finder to track the music folder and move the mp3 files, that really should not be there, after the mp3 CD had been burnt, into another directory outside iTunes. Then I in iTunes scrolled through the list in the album, and it showed an exclamation mark for every song that was gone. Then I in iTunes picked them all out and moved them to the bin. The figure above shows the an album in the Music folder (left) and the almost same album as seen in the playlist.

mp3 CD in 2011?

Everybody else made mp3 CDs ten years ago. But it's only now that we in fact have two units that play them! The car stereo and the Denon CEOL. The second doesn't need mp3 CDs since it streams. And the car radio also has the aux input that takes music from iPad or iPhone's headphone outputs (see blog 028). But a few mp3 CDs in the car doesn't hurt, and makes it possible to see the song names in the car's display, and control music playing by steering wheel buttons. And since there's no USB memory stick input that would have obsoleted the mp3 CD, we will have to use standard CD, mp3 CD or aux input.

I wanted to extract the mp3 CD from our iTunes music collection.

Some more points

Some mp3 songs also all of a sudden appeared twice in the iTunes list, pointing to the same mp3 song. One lits entry has to go, so delete it, but do answer "yes" to the question whether you want to keep the file. I didn't realize and did kill a song or two. Some day I'll learn when I try to play it. Then it's going to be good with the synched backup I have!

If an album comes up with exclamation marks just by itself, it's only the list entry that's been added. Delete the exclamation mark lines only, since the mp3 file in itself is not repeated. Two files can't have the same name in the same directory.

Don't they want me to make mp3 CDs?

Probably not! Am I not supposed to make mp3 of purchased music? I think it's only ripped CDs that may be stored as mp3 out of the box, provided I had imported them to mp3.

I still haven't finished the clean-up! Some 40 albums take time! I really feel stupid.


Don't convert to mp3 if you want to burn an mp3 CD. Take the onces it has for you. Be sad and tell Apple.

But is there another way?

If there is something really wrong with what I did wrong, please comment! Like, if it's so wrong and it would have been easy to get it right, had I hit the right action trail immediately. Right?

Reported to

029 - From ceramic vase to cutlery drainer

Moved to

Tuesday, July 19, 2011

027 - Experiencing Apple AirPlay

This note is updated at my new blog space only, blog note Welcome there!

Updated 27Sept2012 (after iOS 6 update to AppleTV), chapter "Playing from and to different devices"

Referring to blog 019 - we ended up with a Denon RCD N7 Network CD Receiver (CEOL). I gave up on Sonos. I got real AirPlay instead. Now we can listen to music at places and by combinations I hadn't read myself to know. Let me go on from blog 019:

Denon RCD N7 (CEOL)

This was bought at Hi-Fi klubben here in Trondheim in July 2011. Bringing it home, the first non-power cable I connected was the home network's ethernet cable. Joy! The only cables I plugged out from the 20 years old Denon Precision Audio Component / AM-FM Stereo Receiver DRA-335R were analogue. It has been tired some years now, together with the Denon PCM Audio Technology / Compact Disc Player DCD-680. Both were also bought at HiFiKlubben back then, and will now be stacked on the loft. Hard to scrap a friend.

The Ceol took charge and asked me if I wanted to update its firmware. Yes, I did - and it did the job in some 30 minutes.

I had bought the thing for its AirPlay capability (there are plenty other nice boxes without), and went to First I had to pick out our unit's serial number, MAC address and upgrade ID. Paying with PayPal has always been a pleasure, so I expected the Ceol to be my everything's remote speaker any minute. For 48€ I thought it should. It didn't. Even if I got a receipt that all was fine - and in the background: Apple had got their licence fee. Since I get a salary every month I don't protest if others want some, even if they put it in the bank.

The Ceol told me I could upgrade with AirPort, ok. I pushed the right menu entries, and it said Authenticating for a minute, an hour, a night. All it accepts then is a power off, so I retried. Nope. A letter to HiFiKlubben and a reply from support adviced me to restart to factory settings. The updated firmware and the 48€ investment should be fine. In the manual it's called "Resetting the microprocessor: unplug the power cord, then hold volume up and down simultaneously and plug in the cable, then release the buttons". However, I used the slightly different procedure in the support email: "Total reset (to factory settings out of the box / virgin mode) 1. Switch Off the unit and unplug mains plug from wall outlet. 2. Press and hold both Volume up and Cursor down buttons on the front panel and plug the mains plug into the wall outlet. 3. Release the two buttons."

This worked perfectly (as probably would have the manual's recipe?): AirPlay soon was in the box. And everywhere! Running Apple's Remote app on the iPad now, the iTunes library comes up as usual, but both the Ceol and the computer come up! I get "surround sound" that I did't know. The tv speakers with nice bass sound (from JackOSX router on the Mac Mini, see blog 019) also appeared. And they are in phase (thanks to some clock synchronization messages in the AirPlay protocol I believe).

Now Gary Moore's Ballads & Blues 1982-1994 plays like music has never been heard in this house. At the moment: bliss.


After a month's use I'd say I'm pretty satisfied with AirPlay. But there are some repeating weak spots:
  1. Sound level at connection.
    I still haven't figured out why it comes on with an enormous volume some times. So, if the amp is more powerful than the speakers, the AirPlay start-up volume may destroy your speakers! For me, it's ok, though.
  2. Sound level up when down or down when up
    The app volume control and the real volume may be out of synch before I have touch the app's volume control. So, when I try to push the volume down (from a shown high volume), it increases (from the unit's low volume) - so that the overall effect is increased volume! Aften that up is up and down is down.
  3. Broken connection.
    Some times one of the AirPlay "speakers" fall out, and I'd have to manually reconnect.
  4. Speakers out of phase.
    One time, while iTunes (version 10.4) converted a bunch of songs to mp3 (and was very busy in one of its "threads"), and it was playing a song simultaneously - the speakers went out of synch. I know this, since it was easy to hear. I would guess 50 ms since it was not that much.
  5. "Connecting to AirPlay unit" when envisaged as already connected.
    Every time I find a new melody it seems to disconnect and then needs some extra time to reconnect. I experience this as not necessary.
  6. Outdated display.
    I have seen Denon not display the present melody, when I played iTunes through the Remote app. Didn't iTunes send it, or didn't Denon update? It stayed with the other day's melody through a whole playing session. At the moment I dont't know what updates it.
Reported to I have found no similar feedback link to Denon.

Playing from and to different devices
We finally (in July 2012) bought an Apple TV unit. This chapter does not discuss the Apple TV per se, but how AirPlay works . The figure above does not show all details, and I have done some shortcuts. Have a look at note 019 for more details (but not updated with Apple TV).

I am most concerned with when the sound is synchronized (playing without relative delays between individual units) in this note. Mirroring the screen is only possible to one screen, I assume. Anyhow, I can listen to sound from many speakers (connected to several amplifiers) but only want to see one screen at a time. The iPad and iPhone (as well as OSX Mountain Lion, which I don't have) can mirror the screen over AirPlay. That is just so nice.

Is the unwanted delay caused by the HDMI? The screen is a Samsung RE26E0 TV (from 2005-06). The unwanted delays I am describing here may have to do with the internal D/A-conversion delay for the HDMI cable. But then, shouldn't that also have given reckognisable delay for the HDMI from the TV tuner? See discussion thread "AirPlay audio sync issue" here (thanks, Anders!). That thread also mentions that AirPlay has a buffer delay of 2 seconds, so there should be no delays between the immediate outputs from any AirPlay unit. If I only had an optical input D/A converter to test the Apple TV's direct output.

YES! It helped to remove the default value of the programmed delay in the Samsung TV! Here's the help that Anders (again) dug out. See post 5 in there as to how to start the service menu. Then the Samsung RE26E0 TV menu was like this (the TV runs as normal with picture and sound):
  • From post 5: "Turn off the TV then press Info -> Menu -> Mute in sequence then turn the TV back on again. This will get you into the secret Service Menu." (I had to fiddle a little to get it into that mode)
  • Ok, here's the top of the secret Service Menu:
  • Select "6. STV8257/STA323W"
  • I set "HDMI Delay" from "41H" to "00H" (41 Hex is (4*16)+(1*1)=65)
  • I also set "PC Delay" from "41H" to "00H"
  • There was no "save config", so it was saved immediately
Then the delay through the HDMI port was zero! AirPlay has always been working!

CASE 1: Playing sound from Apple TV
  1. Since I don't use the optical sound output from the Apple TV, the TV has to be on to get the sound to any speakers from the Apple TV. This is no problem, we need its screen anyhow.
  2. (Obsoleted: With sound from Apple TV, only the green (left) speakers may get sound. Not the two others!)
    New with iOS 6 upgrade on AppleTV (late Sept. 2012): Now it is possible to send AirPlay music to the other AirPlay units! It's also possible to adjust the volume with the AppleTV remote control on the AppleTV.
  3. The green speakers are volume adjusted with the TV remote control. Apple TV has no volume control (not true for AirPlay outputs with iOS 6, see last sentence in bullet above.)
  4. Observe the difference between playing from Apple TV and playing with Apple TV. More below.
CASE 2: Playing sound with Apple TV
  1. As I mentioned in the topmost chapter, playing from the Mac Mini (with iTunes) into the blue speakers (center) and the black Denon speakers (right) are completely synchronous. The Mini runs Lion, not Mountain Lion. The latter can mirror its screen to the Apple TV. Our Mini is too old for that.
  2. If the following happens to you then try to check the HDMI delay, see above, to see if you can get rid of it. (I try to leave traces of the path to a solution in my blogs, and this is a paragraph "on the road":) "However, adding the Apple TV as the third speaker is not useful, since there is a reckognisable delay. It's not at all in synch! Routing the sound to Apple TV in this case does not make sense."
CASE 3: Playing from iPad or iPhone and Mini
  1. When selecting AirPlay units from iPad or iPhone, the Mini output (blue, center) does not appear.
  2. This is easy to understand, since Lion is not a first class citizen of AirPlay.
  3. When I run iTunes on the Mini, however, "This computer" appears as a selection - in addition to the other two.

Saturday, July 2, 2011

026 - iOS picture sorting and file system do not tango

(2 July 2011, updated 24 October 2011)

This note discusses synching pictures on iOS units (iDevices) by letting iTunes use a disk directory for picture synching. It does not initially deal with having iTunes synch using iPhoto, but I plan to also handle that. I use Mac OS X Snow Leopard. I will update this note as time goes. If it's not been updated, it's probably because I haven't seen anything new.

iOS sorting by modification date only
Update 24.Oct.2011 with iOS 5.0: Apple seem to have gone back to alphabetical sorting again! However, in view of what I have written below, maybe they now have combined sorting methods, as I have suggested? 
Apple has decided that the iPad, iPhone or iPod (all running iOS) pictures and movies shall be sorted according to last modification date and time. It didn't start that way, but has been like that since iOS 4.

I would perhaps want iOS to let me select sorting method. Letting me choose alphabetical sorting could have been great, provided it worked. Since the alphabet I use is sortable (!?), it's a nice feature that our culture has become accustomed to. However, since camera picture names contain a number, the series would sooner or later wrap around: DSC_9999 would become DSC_0000. So any number would repeat, making alphabetical sorting difficult. And no matter how much time increases, it only seems to wrap at each big bang(?). (Being an embedded programmer I know that having a finite word length, counting the number of system clock tics does indeed overflow to zero. But that's why we're there, to know about these things.)

Maybe combining some date/time and alphabetical sorting would have been smart? The engineers at Apple of course know that being smart some times is not always that smart. The framework in which to be smart may change, and in the new context it wasn't smart any more.

So, sorting photos by date/time has come to stay. I'll have to take it in.

Vacation pictures oops.. changed!

If I change a file, cropping it, resizing it, change the light or anything, then it would now cause that picture to get today's modification date/time. Synching it with iTunes to an iOS unit would place it down at the bottom in the sorted list.

So I need to overwrite modification date by creation date

I found an AppleScript that does exactly this on the net [1]. I'll call it "TheScript" from now on. Perfect, now the photos are in lane again after the next iTunes synch also. But hey, finding it, downloading it and start to use it is not simple in any context, Apple?

Say the disk directory where iTunes finds the pictures is on a local disk, and say that TimeMachine is used for backup, then all is fine.

However, if the picture directory is on a network disk, or if as above without TimeMachine as backup, or if not only backup but also synchronization is used, then I may have a problem.

My synch program may push my pictures out of lane again!

Synching disks and synching iOS units with  iTunes are not the same thing. I'll try to be precise below. Later in 2011 Apple iCloud synching will happen without iTunes.

Skip this chapter if you always plan to run TheScript before you synchronize the disk with another disk, after having modified a file.

To get disk synchronization to work, modifying a set of files should be "atomic" with respect to disk synching. So, make yourself non-disturbable in that phase. A modified file should not be synched before TheScript!

I'll try to explain the situation that might arise if you modified a file, got disturbed, and then synched the disks "out of synch".

I use an old friend called ChronoSync. I have used it for years to synch several machines, using a network disk as the base. Whenever I change a photo, I do it at some local machine and synch the disks and then let iTunes use the synched base at the network disk for its photo synching.

However, since I have modified a photo and thus made it newer, ChronoSync will (if I run it in this phase) let the newest version survive. Later iTunes iOS synching will place the picture at the bottom.

I have found no way for the present ChronoSync to work this out. A change could be something like this, to be used after file change and we don't have TheScript:
Resolve conflict if two files have equal creation date to use the newest modified file but then change modification dates of both to become creation date
Or, how about a special synch session called iOS picture/movie synching?

I have informed Econ Technologies about this 2July11 ( (And they have replied, stay tuned)

Back to iTunes: re-date alphanumerically sorted files?

I have no way to solve this! The name of all my files have started with som number and then a sentence, like "314 pythagoras.jpg" and "271 e.jpg". The operating system understands that the characters '0'-'9' are treated as numbers and sorted accordingly. I have called this alphabetical sorting, even if it does understand fields. So the 271 file is sorted as the first.

Some times I could learn AppleScript and write a script that solves my problem: keep dates as much as possible, understand modification date and spread the set out over the dates wanted. Sorting by pushing around pictures by hand is perhaps best.. But this is difficult!

Inserting a picture or a movie into the iOS sorting sequence

Some times you need to add a picture into a sequence. Maybe you want a poster in front of each section, or the next country's flag. This is almost easy: 1.) Make a copy of the neighboring file. This has the same creation date. Experiment with the file before or after, it's not obvious how equal date/times are sorted. 2.) Open the new file in an editor. I use Graphic Convertor. 3.) Paste the image you have made prior to this so that it's inserted into the just opened picture, so that all is overwritten. You may have to delete all contents first. 4.) Save the file with the new contents. 5.) Run TheScript to make modification date from creation date.

This works for picture files.

Movies like .mov I have not been able to fix yet. Stay tuned.


[1]MacFileDatesChanger by Daniel A. Shockley, Includes some code from Paul Berkowitz and Nigel Garvey on applescript-users mailing list.


Monday, June 13, 2011

025 - iPad2 on vacation, ups and downs

This blog lists some random experience with using an iPad2 in Italy in the summer of 2011. The iOS version was 4.3.3. Some if these experiences may be of interest to others..

1 - Painting from a picture with a grid ::

I did try paining water colour (aquarelle) again on this visit. Sitting at the spot to draw and paint feels most artistic. However, as the light and shadows, and indeed colours change, it's easy to shoot a picture and use it to paint off-spot.

I took the picture and imported it to the iPad. More about this import scheme later; it does have some peculiar functionality.
Aside: With the newest version of iOS (5 and on) it's possible to get grid in a picture very easily this way: When you view a picture, there is an edit button. Push it, and then push the crop button. Up comes the picture with a 3x3 grid. Screen clip it and use it to paint after! You get the whole screen, with frames and buttons and all, but it's quite usable! If you like it, skip the rest of this note. (Added Feb. 2012)
 Apple surely has listened to my feedback below and made this possible..
It's so much easier to draw the picture to paper if we have a grid. A long arm and the thumb on a pencil is difficult with and iPad. With the iPad and its 4/3 ratio screen, a 4x3 grid is enough. I did not succeed making this in the iPad while the paint was wet, so I taped dental floss on the iPad! It worked, but was not very practical when touch was again needed.

When the paint had dried and I had better time, I found a way to overlay a grid onto a picture, on the iPad - while on vacation:

1. In Apple Pages, make a 4x3 table, with size 16 x 12 cm or as close as you can get. Save it. Turn the iPad to landscape and make the table as big as possible.

2. Take s screen shot (Home and On/Off buttons simultaneously). It is saved in Camera Roll.

3. Open ArtStudio. Load this screen cut from Camera Roll. Crop it. Rescale it to 2048x1536 since this is the internal format that ArtStudio "likes" best. Don't keep aspect ratio, as the table you made in Pages may not be accurately 4/3. Now smart-select (use magic wand) one square (512x512) and clear the contents. This makes it transparent. Do this 12 times. Now you have a 4x3 transparent grid. Save it to the Camera Roll.

4. In ArtStudio, load the picture you want to paint. Make a new layer, and insert the just saved picture in that layer. Save it. Congratulations, you don't need the dental floss any more for this stuff!

I have informed Lucky Clan ( about this - as having a built-in function would have been much nicer. I have also informed Apple (, as a magical "display picture with grid" would have been great! Or maybe there already is an app for this? I have not found any way for Pages to put pictures as table background.

By the way, the picture is from San Gimignano. Also, I did not want to transform the picture inside ArtStudio to make a computer water colour. Would have been nice, but not this time.

2 - Deleting imported pictures from iPad but wanting to keep them in the camera ::

This problem is as simple to describe as the iOS solution is too simple.
  1. The first night we imported the first day's new pictures from the camera. Some were good, some were deleted. We had created one first day photo event. ("hendelse" in Norwegian.) Good!
  2. The next day we imported the second day's pictures from the camera. We were asked if we wanted to import the duplicates. Good. We answered no. We had one second day event. Good!
  3. But the pictures we deleted day one were put into a second first day event. This is not what we wanted!
  4. The third day I understood the problem: it's not possible to delete on the iPad alone! If a picture is deleted from the iPad, it must also be deleted from the camera. However, since that picture had indeed been taken, and today's cameras have enough memory to keep everything for a week or four, having a backup of iPad's deleted pictures in the camera would have been nice.
There could be several ways to implement this. I have some ideas, but I trust Apple to solve this.

Only observe, there could be (like) two cameras to import from. An additional problem is then if there should be(like) two first day events or one joined?

Reported to

3 - Using the iPad Navigon app for navigation in the car ::

I have informed a Navigon support mail address about this blog.


We were using Navigon 1.8.2.

This picture shows a typical problem we discovered. We're not certain who's wrong here, but we got it wrong. Here's the route:
  • Via Pisana, 5**** Poggibonsi → Via San Gimignano, 53036 Poggibonsi
  • navigonITA://route/?target=address//ITA/5****/POGGIBONSI/VIA%20PISANA//11.13664/43.47654&
I have isolated the problem to around this roundabout. The routing is fine, but starting from the green flag the voice tells us to:
  1. First take the second road in the roundabout
  2. Then take the third road in the roundabout
We did 1. as told and went up the yellow road. It discovered we were wrong and correctly took us back to the roundabout coming in on Via Galileo Galilei, the white road. It then told us to take the second road, which was correct. But it still asked us to take the third in the final roundabout.

If Navigon is right, then it did not count the white road coming into the first roundabout - but it did count the north white road in the second.

Disclaimer: I don't really know if the map corresponds 100% with the roads, but I think so.

Only going to first entry of route?

I think a Navigon "route" is a list of targets that we can only jump into at one place: the first entry. So, if you have made San Gimignano, no special street, the first entry in the route nad want to go from "here" there is a danger that you'll use 15 minutes trying to reach the first entry from here, like telling Navigon to to go from home to some neighbour. It's made for this kind of stuff, but the Navigon people could probably detect this, and ask me if I wanted to go to the first or second entry in the route. And then next time, I could tell it to go from here to the third entry. And then I would not have to cut off the next goal once I've got there. Maybe this is not what Navigator software is about, maybe others have this, and maybe even Navigon has it? Bare with me: I am new to this!

Map errors

There were obvious map errors, mosty associated with temporary changes. NAVTEQ certainly has some work to do there.


Navigon contains no help whatsoever(?). Touch is not logical, it has to be learnt. Swiping! One, two, three or even more fingers. There is some common reaction to them among apps, but I'd certainly like to know from day one, or minute one, how they are used by Navigon. Tip for Navigon: download ArtStudio. They have a single help screen called "Quick tutorial" and courses called "Lessons".


Some times Navigon crashed and we had to restart, like once every two hours. It came back to where we were, but I certainly hope that Navigon has asked iOS to ask me to send crash logs back to them. Once simulation hung and Navigon did not respond. What I then did was terrible, next chapter.

Post script: another experience with Navigon

Have a look at this note: 028 - DIY prototype of an iPad 2 holder for car glove compartment. The bottom chapter there also comments on Navigon and the car's built-in navgiation.

4 - Too easy to fatally remove an iOS app, when only stopping it was the intention? ::

I deleted Navigon, the navigation software that we relied on, with my finger one late night. When I switched in the brain, it was too late. Norwegian iPad screens, but you should reckognize them ok:

Then I decided that this was partly Apple's fault, even if I hadn't done my homework (stay tuned).

I was tired and pressed buttons in a frenzy when my fingers took the wrong path between wobbling icon with a red minus (top in figure, to kill or stop a program) and a wobbling icon black cross (bottom in figure, to remove a program and its data) makes all the difference.

Navigon was hanging, and I wanted to stop the thing. I should have taken the top path in the figure above, but it's difficult to get there: 1.) While the misbehaving app is running I have to double-tap the home button get to the running process list, 2.) I have to start another application, 3.) I have to double-tap again to get the running process list again, 4.) I have to hold the icon of the app which I want to kill (because only now it appears in the list) so they all start wobbling and then 5.) tap the cross, and that's it. No problem. Green arrow. Can't go wrong because it only stops the app.

However, the mere complexity of the procedure above is so, that when you know how to do it, you do it cognitively without the brain. It's called routine.

Navigon was hanging, and I wanted to stop it. But at that time I chose the wrong path (which is much simpler than the above. Yes, simpler to get to the dangerous thing than the ok thing). A.) I pressed the home button once, B.) I held the icon until it started wobbling and then, C.) I had to answer something in a query box, either D.1) Yes I want to delete the application and all its data or D.2) No I don't. I pressed Yes. Red arrow: very stupid. Good for us that Navigon wasn't showing us the way to a hospital.

However, my home work should have been to set restrictions, which would have stopped my ability to remove a program! The black crosses simply won't appear no matter how long I hold an icon. See figure below. I had thought this was something that parents did with a kid's iDevice. Now I understand that it's certainly something I should have done to protect myself from my own stupid actions. And from Apple's elegant but dangerous route - even if by design.

For our case it really wasn't so bad, though. I had also installed Navigon on my wife's 3GS, and we could happily drive on. And the hotell we arrived at in Urbino, Italy, had internet access included. Up with AppStore on the iOS, and a new almost 2 GB download. It's perfect that one purchase covers several machines, and that Navigon exists for both machines!

But Apple - the whole of Navigon was probbaly still silently present in the iOS flash-based memory. How about just asking me if I wanted to wake up the just deleted app? I don't know if the iOS file system has a recycle bin internally, but the functionality would have been nice! Or a third choice to removal, yes, cancel or stack (move to some kind of iOS special recycle mechanism?).

I have reported this to

5 - mail squelched on some routers ::

Usually it works surprisingly well to connect iPhone, iPod or iPad to a new router. However at one of the hotels we experienced problems with mail. Browsing with Safari (and Opera) worked fine. But sending and receiving mail with the iOS mail client failed. More detailed: sending always failed, bet reception a very few times seemed to work. We brought one iPad2 (iOS 4.3.3), one iPhone 3G (iOS 4.2.1) and one 3GS (iOS 4.3.1) - but I only experimented on the iPad.

I think and the router in mind together displayed the problem. Not only the Mail client, but even Safari webmail was not able to log in to my account. Opera Mini webmail with logged me in and I could read mail and also send (see below).

We had one ingoing IMAP server connected, and up to three outgoing SPMT servers. Any combination of these did not seem to help.

I don't know if the router had blocked IMAP incoming port 143 or SMTP outgoing port 25 or 587. I tried to test, and all ports looked blocked, even standard browser HTTP port 80. So, I must have used the tool wrongly, or it

The strange thing is that I wasn't able to set up Gmail in iOS Mail either, even if it's more or less automatic and built-in. Another strange thing: why did the lady I asked, sitting with an iPad, have functional mail, in the same hotel?

[1] "Setting up iPhone Mail/iPod Touch" help on This is not updated with iPad, which is a shame. They don't support home page editing for Mac either, any type - Mac OSX or iOS. Another shame.

6 - Opera Mini browser and webmail ::

The Opera Mini was version webmail did work to some extent with the particular router, mentioned above. But there are some points, most of them disregarding the fact of the router, I would assume.
  1. Opera Mini could only handle one session "per Opera". Different windows were not able to have different log-ins or sessions. This mixed up the webmail lists, which pointed to the last log-in list. So, if my wife logged in in one window, and I was already logged in in another - when I came back to mine and pressed mail #3, it confused that with entries in her list.
  2. As when using iOS Safari at home (or at the other hotels) webmail sending of file attachments does not work. Both browsers would know perfectly well that this browser is for iOS, so giving me a possibility to browse pictures should have been piece of cake.
  3. Opera Mini hindered me editing the file input line, which proves that they knew it is of little use.
  4. Opera Mini let med pick out the Send text from the Send button, as if that is of any interest.
  5. Opera Mini could not show pictures in mails.
I have another blog about Opera Mini here: 017

Tuesday, March 8, 2011

024 - 16:9 video aspect ratio with width 720 uses height 404 instead of 405

iPhone movies..
The iPhone 4 produces QuickTime HD movies (.mov) that are 1280 x 720 pixels (16:9 aspect ratio). Observe that this is not the screen aspect ratio, which is 960 x 640 (3:2 or 1.5). Here is a nice comparison: (but speculative about iPad3). not play on all machines
This is very nice. I can play it on my Mac Mini running Mac OS X Snow Leopard and QuickTime Player 10.0. However, the iBook and iMac (lamp) G4 machines running Mac OS X Tiger with QuickTime Player 7.6.4 only plays the sound but shows the odd picture as it moves on.
But QuickTime Player export to "HD 480p" helped
So, I exported from the newest QuickTime Player to a "HD 480p"-type file. This plays beautifully on the older Tiger machines. The movies turn out to be 640 x 360 pixels (16:9). The movies were brighter and better looking than corresponding mpeg-2 (.mpg) movies in 640 x 480 (4:3 or 1.33..) shot with a Sony DSC-W100. And somewhat smaller in file size, I think.
I have also seen some movies that have been converted to 985 x 544 pixels, which is approximately 16:9. See below. I doubt that this is a result og HD 480p export, though?
And I think that 480p is 640 x 480 in 4:3, but I have not tried. But Panasonic Lumix DMC-LX5 takes several formats, so I will try one day.
However, export to "HD 720p" intrigued me
But I wanted to try to see how export to "HD 720p" ran on the Tiger machines. Better, but really not. I could accept that. However, I saw that this movie was 720 x 404 pixels, a little more than 16:9. I used the lazy solution at Evalwave Factors at to factorize.
First, 16:9 is 1,7777777777.....
720 = 2 x 2 x 2 x 2 x 3 x 3 x 5
404 = 2 x 2 x 101
removing common factors 2 x 2 yields
180:101 = 1,78217821782.. is almost 16:9
How about one more pixel (404+1) on the short side:
720 = 2 x 2 x 2 x 2 x 3 x 3 x 5
405 = 3 x 3 x 3 x 3 x 5
removing common factors 3 x 3 x 5 yields
So, why is 720 x 404 used?
Kyle Gilman's page opens a door for me: "Keep the height an even number. Odd numbers freak out the H.264 codec. In this case 720×405 is closer to 16:9, but change it to 404 and everyone will be happier."
Some day I'll investigate more about the H.264 codec.
However, I do remember from the time I did Fast Fourier Transforms that even numbers were required (even if there are odd number algorithms available). And hardware multiplies by two by shifting left by one bit. This is much faster, and does not build up any errors.
Screens certainly must show the missing 405th line as all dark! Or the other way around, the iPhone (or, really H.264) throws away a line?
Another example is 568 x 320
My daughter sent me this iPhone movie by mail, directly from the phone.
568 = 2 x 2 x 2 x 71
320 = 2 x 2 x 2 x 2 x 2 x 2 x 5
removing common factors 2 x 2 x 2 yields
71:40 = 1,775, some 0.0277777.. off 16:9
What is the "real" 16:9 numbers here, i.e. how much is lost? Around those values there are lots of prime numbers, which are never even. Moving one up or down by 1 does not get me there.
I certainly need help here!

Thursday, February 10, 2011

023 - Concurrency: one writer and one reader is bad enough

Error on page 15 of IEEE Software Jan/Feb 2011

Dear Forest Shull (editor of IEEE Software)

There is an error at that page, in the article “Parallelism on the Desktop” (Guest Editors’ introduction: Victor Pankratius, Wolfram Schulte and Kurt Keutzer [1]). The authors have virtually fallen into the same trap as many programmers working with concurrency or parallelism.

“If the shared resource is mutable, programmers must introduce exclusion mechanisms, such as locks in C++ or synchronized methods in Java, to prevent race conditions (where two or more threads change the resource at the same time and introduce an inconcistent state).”

In order to be correct, the last part may instead read: “where even a single writer and a concurrent single reader may introduce an inconcistent state”.

The principle is called CREW (Concurrent Read Exclusive Write), see,_concurrent_write: “Concurrent Read Exclusive Write (CREW) — multiple processors can read a memory cell but only one can write at a time”.

The idea of the concurrency primitives is to avoid this type of situation. In the problem domain, CREW shows how bad it is. In the solution domain, it would be the accesses (read or write) that need protection if there is at most one writer.

I may blog about this error at any day soon. (Done, with minor edits.)

[1] - Read pdf (4 MB)

(29June11: no response to the contents)

Sunday, January 9, 2011

022 - C1X and C++0x concurrency in C and C++ Working Drafts

Updated 15Aug11


The scope of this post is to learn how the renewed C and C++ standards may help programmers of concurrent systems do their job. I will of course look at this through my CSP-type glasses, with years of occam programming and using CSP/channel-type libraries in ANSI C in embedded systems as my bias. (Post 021- The problems with threads takes me up to this point.)
  • I assume that C1X should end of with C12 for the year's publication data ("formal adoption of a revised standard by the end of 2011, with a publication date of 2012" (C - The C1X Charter)). 
  • And C++0x I assume means that they are late, but from the wiki-page is looks like it's going to end up with C++11. As of 12 August 2011, the C++0x specification has been approved by the ISO. The final working draft before final ISO approval standard is N3291, dated 5 April 2011. This draft is not publicly available; the most recent working draft available is (N3242) dated 28 February 2011. So, it's probably going to be called C++11.
Here are the main references:

Letters-in-words and words that I will use to search in the documents. This should(?) indirectly direct me to all the new keywords:
  • "thread"
  • "multi" (task thread -threading)
  • "concurren" (t cy tly)
  • "synchron" (ization, ous, asynchron..)
  • "communicat" (e ion ing)
  • "atomic"
  • " race" (to exclude brace..)
  • "deadlock"
  • "process" (no such term, but there are some threads by name "process")
  • "schedul" (e, ing)
  • "happens before"
  • "inter-thread happens before"
I'd like to see if I could fill in these points:
  1. Process (no: thread) model (versus or and object model)?
  2. Synchronization model?
  3. Communication model?
  4. Memory model - why is there so much about this?
  1. Will the C concurrency features be a subset of the C++ concurrency features?
  2. The difference between third-party thread by library (as discussed in post 021) and language defined thread by library as defined here. Is it assumed that the compiler knows what a process (or whatever) is? The answer to this is a function of what I would see from the above list
  3. Per definition it will it be A Good Thing to build a CSP library on top of these! How "nice" will such a library be, i.e. how easy to get correct? (Again, see post 021)
First comments

My post 021 starts with quoting "It is widely acknowledged that concurrent programming is difficult" (Lee). Future programmers of C and C++ may learn by expensive experience that it is even "very difficult".

These papers start after the climax in the middle of Lee's paper. Where he goes on in the right direction, these papers don't go back to square one. They elevate.

Ok, they add concurrency where there was none before. That is their motivation, and it is an important motivation. But whose idea was it to build this on C and C++? Did they ask?

These people are specialists. The papers are not for amateurs, like I would be in their eyes. I have been hidden from most of the problems they solve during my 30 years of concurrent programming. Starting off with a runtime system in 1980 that we bought from a university person who said his code in PL/M had "no errors". We though he was more crazy than he was! Modula 2 and a runtime system for it. Occam on transputers and occam to C (SPoC). Occam will stay the programmer's love of my life. And then back a few hops to C and CSP-type runtime systems.

I really don't understand which planet the is on when it comes to concurrency. In post 021 Per Brinch Hansen is quoted for "that Java ignores the last twenty-five years of research in parallel programming languages.". How many years will future C and C++ programmers have lost?

I am not able to see the answer to any of the questions above. There may be answers, but they seem hidden for me. Except: yes - C is a subset of C++ still, at least when it comes to the memory model. I think.

A language isn't for the future just because "futures" are implemented. This is a pattern that I could easily code in occam and install some 20 years ago. But it's nice to have it in a language. And it is nice to have atomicity described. Etc.

But it is the complexity explosion of the standard that worries me. Inspired by Lee, they are two vast seas of nondeterminism - used in another domain - the definition-of-standard domain.

This probably is very reasonable (from C++ page 1152):
29.6.5 Requirements for operations on atomic types [atomics.types.operations.req]
6 #define ATOMIC_VAR_INIT(value) see below
Remarks: The macro expands to a token sequence suitable for constant initialization an atomic variable of static storage duration of a type that is initialization-compatible with value. [ Note: This operation may need to initialize locks. — end note ] Concurrent access to the variable being initialized, even via an atomic operation, constitutes a data race.[ Example: atomic v = ATOMIC_VAR_INIT(5); — end example ]
Please help me. And if I am able to understand, then I need help with some more.

But this is rather ok (C++ page 11):
1.10 Multi-threaded executions and data races [intro.multithread]
1 Every thread in a program can potentially access every object and function in a program (10)
(10) An object with automatic or thread storage duration (3.7) is associated with one specific thread, and can be accessed by a different thread only indirectly through a pointer or reference (3.9.2).
Let's say that I want to implement a CSP library, and when the second process is on a channel, I want to do the rendezvous memcpy from inside the sender process to inside the receiver process. So now I know that I may code this. In C or C++. But observe the level. It's underneath where I should be.

But isn't that what has set out to do for me? Make it possible to build any concurrency paradigm on top of what they now give me? Probably they haven't missed that goal. Stroustrup told me exactly this when I approached him at Simula 67's 25th anniversary in Oslo in 1992: C++ does not have any concurrency to let anybody build their own. Now they are building their own.

Last comments

Adam Sampson's thesis Process-Oriented Patterns for Concurrent Software Engineering that he posted in a comment to post 021 certainly points to another direction of research - and present good practices. And I must repeat: the Go programming language faq also referenced in post 021.


Is the world really crying for these two houses built on sand?

What did you say, do you need a C/C++ concurrency expert? If you find a good one, you'd need to wait 5-10 years before you know whether he was as good. And he wouldn't know if the house burnt. Working for other companies, making more good money.

Archive and about

Popular Posts

Øyvind Teig

My photo
Trondheim, Norway

All new blogs and new home page start at

Overview of old blog notes here

My technology blog was at

and my handicraft blog was at

PS: just call me "Oyvind"