WaitForSingleObject and WaitForMultipleObjects equivalent in Linux?

Stick to pthread_cond_timedwait and use clock_gettime. For example: struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 10; // ten seconds while (!some_condition && ret == 0) ret = pthread_cond_timedwait(&cond, &mutex, &ts); Wrap it in a function if you wish. UPDATE: complementing the answer based on our comments. POSIX doesn’t have a single API to wait for … Read more

SQL Server equivalent of substring_index function in MySQL

Try this solution based on T-SQL and XQuery((root/row)[position() <= sql:variable(“@count”)]): T-SQL Scalar function: CREATE FUNCTION dbo.SUBSTRING_INDEX ( @str NVARCHAR(4000), @delim NVARCHAR(1), @count INT ) RETURNS NVARCHAR(4000) WITH SCHEMABINDING BEGIN DECLARE @XmlSourceString XML; SET @XmlSourceString = (SELECT N'<root><row>’ + REPLACE( (SELECT @str AS ‘*’ FOR XML PATH(”)) , @delim, N'</row><row>’ ) + N'</row></root>’); RETURN STUFF ( … Read more

Date command does not follow Linux specifications (Mac OS X Lion)

This is because OSX and Linux use two different sets of tools. Linux uses the GNU version of the date command (hence, GNU/Linux). Remember that Linux is Linux and OS X is Unix. They’re different. You can install the GNU date command which is included in the “coreutils” package from MacPorts. It will be installed … Read more

Port of Random generator from C to Java?

Most of the time there is no need to use larger numeric types for simulating unsigned types in Java. For addition, subtraction, multiplication, shift left, the logical operations, equality and casting to a smaller numeric type it doesn’t matter whether the operands are signed or unsigned, the result will be the same regardless, viewed as … Read more