>

2014년 6월 26일 목요일

std::thread in Mac OS X maveric

Multi-thread programming in C++ with STL is so easy now.

C++ 멀티스레드 프로그래밍 아주 쉬워졌음.

$ clang++ thread_test.cpp -std=c++11 -o thrad_test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <algorithm>
#include <thread>
void executebuf (std::vector<int>& buf, int i)
//void executebuf (int buf[], int i)
{
    buf[i] = i*10;
    if (i==2) // do something
    for (int j=0; j<1000000; j++)
        int x = j*i*i*i;
    fprintf (stderr, "ebuf= %d\n", i);
}
void execute()
{
    std::cout << "Hello Concurrent world" << std::endl;
}
std::string filename;
void execute2() 
{
    for (int i=0; i<1000000; i++// do something
        int x = i*i*i*i;
    std::cout << "Hello Concurrent world 2 " << filename << std::endl;
    filename = std::string("printed");
}
int main() 
{
    std::thread th(execute);
    filename = "this is filename.";
    std::thread th2(execute2);
    th.join();
    th2.join();
    std::cout << filename << std::endl;
    std::vector<int> buf(10);
    std::vector<std::thread> t;
    for (int i=0; i<4; i++) 
        t.push_back( std::thread (executebuf, std::ref(buf), i) );
    for (int i=0; i<4; i++)
        t[i].join();
    for (int i=0; i<4; i++)
        printf ("%d  \n", buf[i]);
        return(0);
}
//EOF//
End.

2014년 6월 9일 월요일

lftp mirror

어떤 ftp 사이트의 내용을 통째로 카피해오고 싶을때 사용하는 lftp의 미러링 방법.

This is when you want to copy all the files in an ftp site.

1. You need lftp installed in your computer.

    $ brew install lftp

2. make a bash file with the following contents. For example, make a file named mir.sh with the following.

#!/bin/bash
HOST="ftp_hostname"
USER="ftp_user_id"
PASS="password_for_the_id"
LOG_dir="/tmp/logs"
LCD="local_dir_where_the_files_go"
RCD="dir_of_the_ftp_site"

for ((;;)) // simply repeat. remove for-loop command if the ftp is very stable.
do

DATE=`date '+%Y-%m-%d_%H%M'`
lftp -c "set ftp:list-options -a;
open ftp://$USER:$PASS@$HOST;
lcd $LCD;
cd $RCD;
mirror --verbose --exclude-glob old/ --parallel=10 --log="$LOG_dir/GPL_$DATE" "

sleep 30m 

done 


3. make the file mir.sh executable:

    $ chmod +x mir.sh

4. run the command

    $ mir.sh

5. Wait until it finishes.

6. Press Control-C to stop the bash process.