Multithreading Prime Numbers in C++ (fake multithreading – sleep timer)

#include<iostream>
#include<windows.h>
#include<stdio.h>
#define MAX_THREADS 3
using namespace std;
DWORD WINAPI primenumber (LPVOID);
HANDLE hThreads [MAX_THREADS];
DWORD id [MAX_THREADS];
DWORD waiter;

void endThreads (int i)
{
waiter = WaitForMultipleObjects(MAX_THREADS, hThreads, TRUE, INFINITE);
//cout << “waiter:(” << waiter << “)”;
CloseHandle(hThreads[i]);
}

int getThreads ()
{
for (int i=1; i <= MAX_THREADS ; i++)
{
if (hThreads[i] == NULL)
{
return i;
}
else if (i < MAX_THREADS)
{
endThreads(i);
}
else
{
endThreads(i);
return 1;
}
}
}

int check_prime(int a)
{
int c;
int check =0;
for ( c = 2 ; c <= a – 1 ; c++ ) //return 1 = send, return 0 = dont send
{
if ( a%c == 0 )
{
return 0;
check = 1;
}
}
if ( c == a && check == 0)
return 1;
}

DWORD WINAPI primenumber(LPVOID Param)
{
DWORD Number = *(DWORD*)Param;
DWORD result = 0;
if(check_prime(Number)==1)
{
printf(“%d”,Number);
cout << endl;
}
return 0;
}
int main()
{
DWORD ThreadId;
HANDLE ThreadHandle;
int inputnumber;
cout << “Please enter a number only”<< endl;
cin >> inputnumber;
cout << “Prime numbers less than “<< inputnumber << “: “<< endl;
for(int i=1; i<=inputnumber; i++)
{
hThreads[getThreads()]= CreateThread(NULL, 0, primenumber, &i, NULL, &id[getThreads()]);
Sleep(1);
//system(“PAUSE”);
waiter = WaitForMultipleObjects(MAX_THREADS, hThreads, TRUE, INFINITE);
}
}

download

Problem without using sleep for thread
download (1)

Problem after insert sleep timer during print the result
DWORD WINAPI primenumber(LPVOID Param)
{
DWORD Number = *(DWORD*)Param;
DWORD result = 0;
if(check_prime(Number)==1)
{
printf(“%d”,Number);
Sleep(1);
cout << endl;
}
return 0;
}

download (2)

Multithreading Prime Number in C++ (another method)

#include<iostream>
#include<windows.h>
#include<stdio.h>
#define MAX_THREADS 3
using namespace std;
DWORD WINAPI primenumber (LPVOID);
HANDLE hThreads [MAX_THREADS];
DWORD id [MAX_THREADS];
DWORD waiter;

int check_prime(int a)
{
int c;
int check =0;
for ( c = 2 ; c <= a – 1 ; c++ ) //return 1 = send, return 0 = dont send
{
if ( a%c == 0 ){
return 0;
check = 1;
}
}
if ( c == a && check == 0)
return 1;
}

DWORD WINAPI primenumber(LPVOID Param)
{
DWORD Number = *(DWORD*)Param;
DWORD result = 0;
if(check_prime(Number)==1) {
printf(“%d”,Number);
cout << endl;
}
return 0;
}

int main()
{
//DWORD id[MAX_THREADS];
//HANDLE ThreadHandle[MAX_THREADS];
//DWORD waiter;
DWORD ThreadId;
HANDLE ThreadHandle;
int inputnumber;
cout << “Please enter a number only”<< endl;
cin >> inputnumber;
for(int i=1;i<=inputnumber;i++)
{
if ((i==1) || ((i!=2) && (i!=3) && ((i)%3==0))){
hThreads[1]= CreateThread(NULL, 0, primenumber, &i, NULL, &id[1]);
//cout << “”;
//cout << “get number (” << i << “)” << endl;
}
else if ((i==2) || ((i!=1) && (i!=3) && ((i+1)%3==0))){
hThreads[2]= CreateThread(NULL, 0, primenumber, &i, NULL, &id[2]);
//cout << “”;
//cout << “get number (” << i << “)” << endl;
}
else if ((i==3) || ((i!=1) && (i!=2) && ((i+2)%3==0))){
hThreads[3]= CreateThread(NULL, 0, primenumber, &i, NULL, &id[3]);
//cout << “”;
//cout << “get number (” << i << “)” << endl;
}
waiter = WaitForMultipleObjects(MAX_THREADS, hThreads, TRUE, INFINITE);
}

// release handles
if (ThreadHandle != NULL) {
for (int i = 0; i < MAX_THREADS; ++i)
CloseHandle(hThreads[i]);}
return 0;
}

Multithreading Prime Numbers in C++

#include<iostream>
#include<windows.h>
#include<stdio.h>
#define MAX_THREADS 3
using namespace std;
DWORD WINAPI primenumber (LPVOID);
HANDLE hThreads [MAX_THREADS];
DWORD id [MAX_THREADS];
DWORD waiter;

void closeThreads (int i){
waiter = WaitForMultipleObjects(MAX_THREADS, hThreads, TRUE, INFINITE);
CloseHandle(hThreads[i]);
}

int getThreads (){
for (int i=1; i <= MAX_THREADS ; i++){
if (hThreads[i] == NULL){
return i;
}else if (i < MAX_THREADS)
{
closeThreads(i);
}else
{
closeThreads(i);
return 1;
}
}
}

int check_prime(int a)
{
int c;
int check =0;
for ( c = 2 ; c <= a – 1 ; c++ ) //return 1 = send, return 0 = dont send
{
if ( a%c == 0 ){
return 0;
check = 1;
}
}
if ( c == a && check == 0)
return 1;
}

DWORD WINAPI primenumber(LPVOID Param)
{
DWORD Number = *(DWORD*)Param;
DWORD result = 0;
if(check_prime(Number)==1) {
printf(“%d”,Number);
cout << endl;
}
return 0;
}

int main()
{
DWORD ThreadId;
HANDLE ThreadHandle;
int inputnumber;
cout << “Please enter a number only”<< endl;
cin >> inputnumber;
for(int i=1;i<=inputnumber;i++)
{
hThreads[getThreads()]= CreateThread(NULL, 0, primenumber, &i, NULL, &id[getThreads()]);
system(“PAUSE”);
}
}

Setup GitHub with Android Studio

Setting up Git

  1. Download and install the latest version of GitHub for Windows. This will automatically install Gitand keep it up-to-date for you.
  2. On your computer, open the Git Shell application.
  3. Tell Git your name so your commits will be properly labeled. Type everything after the $ here:
    git config --global user.name "YOUR NAME"
    
  4. Tell Git the email address that will be associated with your Git commits. The email you specify should be the same one found in your email settings. To keep your email address hidden, see “Keeping your email address private“.
    git config --global user.email "YOUR EMAIL ADDRESS"
    

Next steps: Authenticating with GitHub from Git

When you connect to a GitHub repository from Git, you’ll need to authenticate with GitHub using either HTTPS or SSH.

Connecting over HTTPS (recommended)

If you clone with HTTPS, you can cache your GitHub password in Git using a credential helper.

Connecting over SSH

If you clone with SSH, you must generate SSH keys on each computer you use to push or pull from GitHub.

Sync projects to Github with Android Studio

Click VCS -> Enable version Control Integration -> Git

There doesn’t seem to be a way to add a remote through the GUI. So open Git Bash in the root of the project and do git remote add <remote_name> <remote_url>

Now when you do VCS -> Commit changes -> Commit & Push you should see your remote and everything should work through the GUI.

The git.exe from Github for windows is located in a path like C:\Users\<username>\AppData\Local\GitHub\PortableGit_<numbersandletters>\bin\git.exe1 You have to replace <username> and <numbersandletters> to the actual situation on your system.

Find my git.exe file in my Github folder

In Android Studio you can specify the path to the Git executable at File->Settings...->Version Control->Git->Path to Git executable. Here you have to include the actual executable name. As an example, in my case the actual path is: C:\Users\Raymond\AppData\Local\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin\git.exe

Problems about Windows 10

Problem

  • Cannot connect any file sharing hosts if you sign in with Microsoft Account.
  • Cannot use OneDrive if you haven’t setup OneDrive at the first time.
  • MySQL 5.6.26.0 – MySQL Workbench 6.3.4 x64 cannot run (0xe0434352).
  • RuntimeBroker.exe – Operation aborted
    Capture
  • Start Menu – Tile default app disappeared and appear again after restart.
    Capture

Performance issue

  • Local files sharing Network is slow.

Solution

  • To solve the File Sharing issue,
    1. Make sure the account you are using is registered on the computer that you are going to access. Both computers created same account and both needed sign in with Microsoft account.
  • To solve OneDrive sign in problem,
    1. we can go to setting, uncheck “Start OneDrive automatically when I sign in to Windows.
    2. Restart computer.
    3. Open File Explorer. Click OneDrive.
    It should show OneDrive setup notification again.
  • Capture Capture Capture
  • It is shameful because I realized and found out that my memory stick is failure. Do memtest86
    CSGO installation – curropt update files
    RuntimeBroker.exe – Operation aborted

Unsolved Problem

  • Start Menu – Tile default app disappeared and appear again after restart.

LG 34UC97 Display review

Manufacture Date on May 2015

Ship from Korea

Blacklight Bleeding (Contract Ratio 70/ Brightness 70)

20150803_194401

USB 2.0 Type B cable work on 34UC97 USB hub (tested).

Compare with 34UM95 Manufacture Date on July 2014

I prefer flat panel for less blacklight bleeding, also for 300 less.

Curved monitor doesn’t look cool because you are difficult to see horizontal lines.
It is make me feel strange.

You cant determent if you have a prefect horizontal lines when you PS image.

I do not recommend anyone to get a curved monitor for workstation.

20150803_194401 Untitled

34UC97 Display INF Download

34UC97 TUSB3410 Driver Download