Strange behaviour of std::thread in Visual Studio 2012

Today I came across some strange behaviour with the VS2012 implementation of std::thread. The created thread’s job was to access the XIMEA camera API, one method of thread creation worked ok, and another only half worked.

With the first mode the API could grab from multiple cameras as expected, while with the other it could only grab from one camera – grabbing from the second camera would always fail. To make things stranger the mode that worked required the passing of an un-used argument to the thread function!

Here is the mode that didn’t work:

int t_func() {
	return do_stuff();
}
void start_thread() {
	std::thread t(t_func);
	t.detach();
}

And here is the mode that does work OK, notice the dummy argument that is passed but otherwise unused!

int t_func(void*) {
	return do_stuff();
}
void start_thread() {
	std::thread t(t_func, (void*)NULL);
	t.detach();
}

All very strange!

WPF Application add Console window for stdout etc.

I thought this would be quite hard to achieve, but it turned out to be easy. I wanted my WPF windows app to run with a standard console output so that I could see all tat was written to stdout via printf() etc from some C code that is linked in to the WPF app via a C++/CLI interface. To achieve this it was a matter of setting an application setting as detailed in this post:

http://blog.wpfwonderland.com/2009/03/01/adding-console-window-to-wpf-application/

In summary you just need to change the main App’s ‘Output Type’ setting to ‘Console Application’

Thanks to XAML Wonderland for the post!

Can I use std::thread from a C++/CLI project in Visual Studio 2012

This question seems to produce some confusing and contradicting answers, however the short answer to it is ‘yes, you can’.

You can use std::thread in unmanaged code in a C++/CLI project but not from managed code – but the good thing about C++/CLI is that you can mix managed and unamanaged code.

if you try to use it from managed code you will get an errors like this:

error directive: is not supported when compiling with /clr or /clr:pure.

and this:

error directive: ERROR: Concurrency Runtime is not supported when compiling /clr.

To mark a C++ file as un-managed, go to its C/C++ settings and set its ‘Common Language RunTime Support’ setting to ‘No Common Language RunTime Support’. You can also use the ‘managed’ and ‘unmanaged’ pragmas in your code to do the same, but something about mixing the two in a single file creeps me out!

Possibly the best thing to do is to keep managed code to a minimum (as it’s as ugly as sin) and just use it to interface your .NET code to your native C++ code – which can use std::thread et al. to its heart’s content!

Drupal 7 – Role can’t see unpublished posts, quick and dirty hack

If you want a particular role to see another’s unpublished posts in drupal, then the quickest (and possibility most dangerous) way of achieving this is to grant the role in question this permission:

bypass content access control

It sure aint pretty but it works, use at your own risk!

Linux – General Purpose IO (GPIO) from user space code

I came across this good article about how to program general purpose IO (GPIO) from user space code in Linux

http://falsinsoft.blogspot.ie/2012/11/access-gpio-from-linux-user-space.html

It contains a nice little synopsis of the steps involved with setting up and reading & writing inputs and outputs!

Massive 10GB Magento Database

This is a classic, a venerable magento database was presented to me today – it had grown over time to 10GB and was in danger of being booted right off its hosting due to its wide girth!  I’d say cron hadn’t been run for years.

Anyway its very easy to clean up the magento database, most of the data bloat is stored in a group of log tables and can be just delete right away by running the following queries on the DB:

truncate log_customer;
truncate log_quote;
truncate log_summary;
truncate log_summary_type;
truncate log_url;
truncate log_url_info;
truncate log_visitor;
truncate log_visitor_info;
truncate log_visitor_online;

This reduced the DB size from 10GB to about 150MB.

New Look Website

If you are a repeat visitor you may (or may not) have noticed that we have launched our brand new-look website.  There are still a few tweaks to do so if you notice anything dodge please let us know!

Many thank to Ridge Design, Wicklow for the fantastic web design!

OpenCV Display window title corrupted and multiple windows show

I had a very strange (and annoying problem) with an OpenCV project in VS2012, when my program created an image display window (namedWindow) I noticed that its window title was all garbled and soon afterwards other display windows were created even though the code had not requested them.

I spent a lot of time comparing the VS2012 projects settings with those of another working project and eventually found that I could make the problem go away by adding this to the ‘Preprocessor Definitions’ setting:

_ITERATOR_DEBUG_LEVEL=0

I have no idea at the moment why adding this fixed the problem but it did! I must have added it to the working project (which was born inside VS2010) but I can’t remember why!

C++11 Lambda Expressions

It appears that using lambda expressions in C++ makes me surprisingly happy, they can be positively good for the soul it seems!

RealVNC Server, Android Viewer – Server did not offer supported security type

I had a bit of trouble getting some Android VNC viewers to connect to a Real VNC server on windows 7 today. The most common error message proffered by the viewers while trying to connect was:

Server did not offer supported security type

It seems this may be caused by Real VNC using some non-standard VNC extensions…

Anyway I found that I could get rid of the error message and get the VNC connections to work correctly by changing the following Real VNC Settings (see screen-shot below):

(a) Change ‘Authentication’ to ‘VNC Password’ (and configure a password)
(b) Change ‘Encryption’ to ‘Prefer on’

Note that the second change probably results in the connection being unencrypted so be careful if you are using this on a public network!

server did not offer supported security type