Exemple #1
0
void print_thread_id (int id) {
    try {
        // using a local lock_guard to lock mtx guarantees unlocking on destruction / exception:
        std::lock_guard<std::mutex> lck (mtx);
        print_even(id);
    }
    catch (std::logic_error&) {
        std::cout << "[exception caught]\n";
    }
}
Exemple #2
0
void palin	(char* pStr)
{
		int	len, midndx, left, right, status;

	len		= strlen(pStr);
	STRLEN	= len;
	// Even
	if(len%2==0)
	{
		right	= len/2;
		left	= right-1;
		status	= type(pStr,left,right);

		// left>right
		if(status==1)
		{
			pStr[right]='\0';
			print_even(pStr);
		}
		else
		{
			increment_string(pStr,left);
			if(ALLNINE)
			{
				memset(pStr,'0',sizeof(char)*STRLEN);

				pStr[STRLEN+1]='\0';
				pStr[0]='1';
				pStr[STRLEN]='1';
				printf("%s\n",pStr);
			}
			else
			{
				pStr[right]	= '\0';
				print_even(pStr);
			}
		}
	}
	else
	// Odd
	{
		midndx	= len/2;
		left	= midndx-1;
		right	= midndx+1;
		status	= type(pStr,left,right);

		if(status==1)
		{
			pStr[right]='\0';
			print_odd(pStr);
		}
		else
		{
			increment_string(pStr,midndx);
			if(ALLNINE)
			{
				memset(pStr,'0',sizeof(char)*STRLEN);
				pStr[STRLEN+1]='\0';
				pStr[0]='1';
				pStr[STRLEN]='1';
				printf("%s\n",pStr);
			}
			else
			{
				pStr[right]='\0';
				print_odd(pStr);
			}
		}
	}
}