Panduan Cara Membuat Website GRATIS Untuk Pemula
Tutorial sederhana & mudah untuk membuat website GRATIS bagi pemula dan cara menghasilkan dollar dari website GRATIS
Program Afiliasi Gratis Penghasil Dollar Di Internet
Dibayar Langsung Transfer Lewat ATM, TERBUKTI & GRATIS !!!"
Cara Buat Situs Web GRATIS Penghasil Dollar
SELAMAT DATANG
SEMOGA TUTORIAL INI BERMANFAAT UNTUK ANDA :)!
Tutorial ini disajikan dalam dua bahasa yaitu bahasa inggris (di bagian atas) & bahasa Indonesia (di bagian bawah). Berikut ini adalah tips agar anda dapat memperoleh manfaat yang sebesar-besarnya dari tutorial ini :
* Untuk bisa masuk ke halaman utama, silahkan klik Di Sini
* Pergunakan "Main Menu" untuk menavigasi isi website tutorial ini.
* Sebaiknya anda membaca seluruh isi blog ini mulai dari awal agar anda dapat memperoleh informasi dari tutorial ini dengan sejelas-jelasnya.
* Silahkan anda "save as" isi tutorial website ini ke dalam disket, flash disk, atau hard disk anda untuk membantu anda agar dapat menghemat biaya berinternet & mempermudah anda dalam mempelajarinya secara mandiri.
* Gunakan browser Firefox atau Opera untuk dapat melakukan "save as" isi tutorial website ini. Anda tidak akan bisa melakukannya jika anda menggunakan Internet Explorer. Untuk mendownload Firefox secara GRATIS silahkan anda kunjung www.mozilla.com Kelebihan lain Firefox adalah : Sangat aman & jauh lebih mudah serta lebih efektif pengoperasiannya dibandingkan dengan browser lainnya, selain itu pula, Firefox mempunyai daya jelajah yang lebih cepat karena softwarenya lebih "ringan" dibandingkan dengan yang lain. Oleh karena itulah software ini sangat direkomendasikan sekali oleh Google. Silahkan anda download secara GRATIS !!!
* Untuk mulai mempelajarinya, silahkan anda baca menu "Benefits Of Making Website" agar anda dapat mempunyai semangat yang kuat untuk mempelajari cara membuat website ini, sebab anda sudah bisa mengetahui keuntungan & manfaatnya untuk bisa mempunyai sebuah website.
* Teruskan dengan membaca menu "About Website" untuk mengetahui apa sih sebenarnya sebuah website itu dan hal - hal apa saja yang diperlukan.
* Di bagian menu "Making Website Part I" anda akan belajar membuat website gratis dengan cara yang sangat sederhana sekali dan dengan memanfaatkan webhosting gratisan.
* Setelah anda cukup mahir, teruskan dengan mempelajari materi "Making Website Part II" . Di bagian ini anda akan mempelajari secara garis besar cara membuat website dengan Microsoft Frontpage atau Publisher.
* Jika anda ingin membuat website dengan cara instan, cepat & mudah, silahkan pilih menu "Making Website Part III". Di sini anda akan belajar secara garis besar cara membuat website dengan Instant Page Builder atau Instant Website Builder.
* Untuk mempercantik dan melengkapi kebutuhan website anda, dapat anda dapatkan di bagian menu "Webtools For Webmaster".
* Dibagian "Promoting Your Website" anda akan belajar cara untuk mempromosikan website anda agar bisa banyak dikunjungi orang.
* Untuk mempelajari cara menghasilkan dollar dari website anda , silahkan baca menu "Make Money With Website"
* Untuk melihat bukti bahwa tutorial website ini telah bisa memberikan penghasilan dollar bagi saya sendiri, silahkan lihat di bagian menu "My Comission Report"
Selamat belajar, semoga ketekunan anda dalam belajar membuat website akan memberikan manfaat yang terbaik untuk anda dikemudian hari. Buatlah website yang bermanfaat untuk sesama, hindari materi website yang berbau pornografi, kekerasan, perjudian, dan hal-hal lain yang dilarang oleh agama dan pemerintah.
SALAM SUKSES UNTUK ANDA SEMUANYA :)!
Subscribe to: Posts (Atom)
Google Enter your search terms Submit search form
CO.CC:Free Domain
KATALOG WEBSITE :
* Kumpulan Barang Gratis Di Internet
* Forum Bisnis & Iklan Gratis Online
* Kerja Dari Rumah Bayaran Dollar
* Verify PayPal Tanpa Kartu Kredit
* Tutorial Buat Situs Iklan Gratis
* Situs Iklan Gratis Tanpa Daftar
* Jual Rumah & Tanah Di Sini
* Program GRATIS Penghasil Uang
* Menuju Hidup Yang Lebih Indah
* Penyembuhan Jarak Jauh GRATIS
* Belajar Tehnik Penyembuhan Reiki
* Pasang Iklan Jual Beli GRATIS
* Solusi Alami Untuk Jerawat
* Tehnik Menenangkan Hati
* Program Afiliasi GRATIS
* Lokakarya Atman Yoga
* Sukses Bisnis Di SFI
* Iklan Mini Gratis
* Domain Gratis
PARTNER"S LINK
Free Domain Name - www.YOU.co.nr!
WWW.BUATSITUS.CO.NR
Kamis, 31 Desember 2009
Panduan Cara Membuat Website GRATIS Untuk Pemula
Hack buat pemula
Artikel ini ditujukan bagi pemula, dan disusun oleh pemula. Ditulis untuk pengetahuan semata. Untuk temen2 yg udah ahli, sok aja dilewat, tapi dibaca juga gpp....
Apa sebenarnya hacking itu? klo menurut pengertian gue, hacking adalah ngoprek. Yup, hacking adalah ngoprek, mempelajari sesuatu dengan keingintahuan (curiosity) yg tinggi, ngutak atik sesuatu, 'ngudek-ngudek' sampai ke 'jeroannya'. Sesuatunya apa dong? ya terserah... bisa komputer, mobil, motor, mesin. Tapi masalahnya ada ngga ya hacker mobil, hacker motor, atau hacker pesawat terbang?? hehe... Walaupun saat ini hacking identik dengan 'bobol-membobol', tapi gue kurang setuju klo cuman bobol server orang doang!. Ada yang bilang 'Hacking is Art', trus dimana letak seninya dong? Mau tau pengertian hacking sebenarnya, coba baca artikel sebelumnya (How to Become A Hacker). Di situ dijelasin bahwa hacker berkaitan dengan kemahiran teknis serta kegemaran menyelesaikan masalah dan mengatasi keterbatasan. Contoh hacker pada saat ini yang sering-sering disebut adalah Linus Torvald (tau ngga? itu lho yang menciptakan Linux). Apa dia tukang bobol? belum tentu kan....
Pada artikel ini, gue pengen membagi pengalaman mengenai Hacking, walaupun sampai saat ini gue belum pernah nge-Hack ke server orang. Salah satu cara untuk mencoba simulasi Hack yaitu H3cky0uRs3lf! Buat komputer kita sebagai server (sekaligus belajar konfigurasi server) trus install program yg dibutuhkan. Misalnya klo mo Web Hacking, coba install Apache atau IIS. Atau kita sesuaikan dengan exploit yang udah kita dapet. Tapi lebih baik install Linux atau FreeBSD dulu di komputer pribadi, trus konfigurasi sebagai server, lalu simulasi Hack, setelah itu baru Hack Betulan... Apalagi klo di kost ada jaringan.
Pro dan Kontra Hacking
Pro Kontra
Etika Hacking Semua informasi adalah free Jika semua informasi adalah free, maka tidak ada ladi privacy
Aspek Security Intrusion adalah ilustrasi kelemahan sistem Tidak perlu menjadi pencuri untuk menunjukkan pintu yang tidak terkunci
Idle Machines Hacking hanya pada idle machines idle machines milik siapa ?
science education hanya membobol tapi tidak merusak "hacker wannabe" berpotensi sangat besar untuk merusak
Okeh, sekarang waktunya melakukan aksi...
1. Fase Persiapan
~ Mengumpulkan informasi sebanyak-banyaknya
- Secara Aktif : - portscanning
- network mapping
- OS Detection
- application fingerprinting
Semua itu bisa dilakukan menggunakan toolz tambahan seperti nmap atau netcat
- Secara Pasif : - mailing-list (jasakom, newbie_hacker, hackelink, dsb)
- via internet registries (informasi domain, IP Addres)
- Website yang menjadi terget
2. Fase Eksekusi
~ Setelah mendapatkan informasi, biasanya akan didapatkan informasi mengenai OS yg digunakan, serta port yang terbuka dengan daemon yg sedang berjalan. Selanjutnya mencari informasi mengenai vulnerability holes (celah kelemahan suatu program) dan dimanfaatkan menggunakan exploit (packetstromsecurity.org, milis bugtraq, atau mencari lewat #IRC).
~ Mengekspolitasi Vulnerability Holes
- compile eksploit -> local host -> $gcc -o exploit exploit.c
$./exploit
# hostname (# tanda mendapatkan akses root)
remote host -> $gcc -o exploit exploit.c
$./exploit -t www.terget.com
# (klo beruntung mendapatkan akes root)
~ Brute Force
- Secara berulang melakukan percobaan otentifikasi.
- Menebak username dan password.
- Cracking password file
~ Social Engineering
- Memperdayai user untuk memeberi tahu Username dan password
- Intinya ngibulin user....
3. Fase Setelah Eksekusi
~ Menginstall backdoor, trojans, dan rootkit
~ Menghapus jejak dengan memodifikasi file log agar tidak dicurigai admin
~ Menyalin /etc/passwd atau /etc/shadow/passwd
Nah, intinya seh cara masuk ke server seseorang seperti fase diatas. Mencari informasi, temukan exploit, dan tinggalkan backdoor. Cuma masalahnya hacking bukanlah segampang cara-cara diatas. Itu hanyalah teori, banyak hal yang harus diperhatikan jika ingin mempraketekkan hacking ke server seseorang. Jangan sekali-kali mencoba2 hacking ke server orang tanpa memperhatikan anonimitas (apalagi klo connectnya lewat komputer pribadi tanpa menggunakan proxy). Ntar klo ketahuan bisa repot. Saran gue, cobalah pada mesin localhost dulu (komuter pribadi), klo terhubung ke LAN lebih bagus. Sediakan server yang khusus buat dioprek. Selanjutnya terserah anda.........
Diposkan oleh Cracker
Internet menggunakan Haier C6000 dengan kartu flexi
di 16:51 | 1 komentar
Yang suka banget chatting, punya komputer dan punya hp haier c6000 paketan dari flexi... hehehe coba aja chatting menggunakan komputer dan handphone haier c6000. Saya akan coba bahas caranya.. tapi sementara koneksinya cuman pake kartu flexi aja yahh.. hehe soale cuman itu kartu cdma yang aq punya. Meski sebener nya handphone Haier C6000 bisa di gunakan untuk kartu CDMA laen. Karena handphone ini bisa di unlock meski di jual dengan paketan kartu perdana flexi.
1. Siapkan komputer, hape dan kabel data mini USB. (kabelnya bisa di beli di toko komputer atau toko hape. Biasanya kabel buat card reader juga)
2. Download driver USB nya
3. Instalasi driver nya ke komputer.
4. Buat setting koneksi ke internetnya.
* Masuk ke Control panel
* Cari Network Connections lalu buka (klik 2x)
* Trus di menu File pilih New Connection
*** Settingan di atas untuk koneksi volume based. Untuk koneksi time based anda gunakan user telkomnet@flexi-time
* Setelah membuat setting koneksi dial nya sekalang coba lakukan dial.
Selamat menikamati
Diposkan oleh Cracker
Cara “hack” facebook. Membekukan/Freeze, Melihat Foto Private Profile/Bukan Teman
Author: admin - Kirim ke Teman - 99,192 views
26 Jun
AddThis Social Bookmark Button SocialTwist Tell-a-Friend Share
Iklan Jual - Beli Otomotif Gratis
Ads by resep.web.id Informasi pasang iklan
Hanya mengKlik iklan, anda akan dibayar : Infonya Klik Disini!
Indonesian Social Network
“Hack” Facebook Membekukan/freeze
Mau iseng? begini nich cara nge “hack” atau membekukan account Facebook Membekukan/freeze. Caranya mudah banget, silakan download softwarenya disini atau disini. Setelah didwonload, exstract filenya dan jalankan.
Cara pakai:
1. ketikkan email target pada Form eMail
2. Klik Frezee
3. Tunggu sampai proses selesai / 100%
4. Efeknya account yang di Frezee tidak akan bisa login, jika anda suah merasa “puas” dan ingin membebaskan target silakan klik “stop freezer”.
freeze
Aplikasi untuk mencari File MP3, Video, Lirik di Facebook : http://apps.facebook.com/audiossearch. Silakan Gunakan aplikasi ini untuk mencari dan mendownload MP3 dari Facebook. Bergabung di Groups Aplikasi ini disini!
Melihat Photo Pada Private Profile/Bukan Teman
1. Login
2. Klik disini!
3. Klik “Allow” untuk setuju dengan ketentuan dan kebijakanAkan keluar tampilan seperti dibawah: Paste kan target ID dan klik “Get Photos”
fb-private
Selamat mencoba, mudah-mudahan masih bisa/belum di patch
sumber: dari berbagai sumber
SEO Kontes
Facebooknya Indonesia, The Indonesian Social Network.
Dapatkan banyak teman baru disini!, Dengan Aplikasi IM Chat dan Chat Room, Sharing Video/Mp3, Blog Dll
Daftar Disini!
Segera bergabung dengan FORUM kami, Daftar !
Sela waktu dikantor, isi dengan berTrading Forex di Marketiva
1. Membuka Account Gratis. Daftar Disini!
2. Mendapat $5 Gratis.
3. Hanya dengan $1 sudah bisa bertrading.
4. Keamanan yang cukup bagus.
5. Memperoleh Software untuk bertrading secara real time.
6. Tersedia support berbahasa melayu.
7. Mendapatkan uang virtual, untuk latihan trading
Tutorial 1 | Tutorial 2 | Tutorial 3 | Tutorial 4 | Tutorial 5 | Tutorial 6 | Tutorial 7 | Tutorial 8 | Tutorial 9 | Tutorial 10
Related posts:
1. Cara Mencari File Mp3, Video, Lirik di Facebook dan Mendownloadnya
2. Facebook di Blok Kantor, Begini Cara Mengatasinya
3. Cara Download Video di Facebook
4. Download Mp3 Gratis ST12, Geisha, Zigaz, She, Seventeen, The Potters
5. Cara Cashout Dari Program Bux.to
6. Download Mp3 Gratis Nidji, Peterpan, Wali, Ungu, Saykoji, D’masive
7. Download Mp3 Gratis Nidji, Dewa, Slank, Gigi, Padi, Godbless, Iwan Fals
8. Download Mp3 Gratis Krisdayanti, Agnes Monica, Rosa, Ruth Sahanaya, Dewi Sandra, Dewi Dewi
9. Aplikasi Facebook : PayPal WishList, Join dan Dapatkan Bonus $100 dari PayPal
10. Trading Forex Dengan Modal Kecil, Dapatkan $5 Saat Registrasi!
# Filed under: Komputer & Internet
Pay Per Click Indonesia
Ads by resep.web.id Informasi pasang iklan
* RSS feed for comments on this post
* TrackBack URI
Cara “hack” facebook. Membekukan/Freeze, Melihat Foto Private Profile/Bukan Teman
Cara “hack” facebook. Membekukan/Freeze, Melihat Foto Private Profile/Bukan Teman
Author: admin - Kirim ke Teman - 99,192 views26 Jun
“Hack” Facebook Membekukan/freeze
Mau iseng? begini nich cara nge “hack” atau membekukan account Facebook Membekukan/freeze. Caranya mudah banget, silakan download softwarenya disini atau disini. Setelah didwonload, exstract filenya dan jalankan.
Cara pakai:
- ketikkan email target pada Form eMail
- Klik Frezee
- Tunggu sampai proses selesai / 100%
- Efeknya account yang di Frezee tidak akan bisa login, jika anda suah merasa “puas” dan ingin membebaskan target silakan klik “stop freezer”.
Aplikasi untuk mencari File MP3, Video, Lirik di Facebook : http://apps.facebook.com/audiossearch. Silakan Gunakan aplikasi ini untuk mencari dan mendownload MP3 dari Facebook. Bergabung di Groups Aplikasi ini disini!
Melihat Photo Pada Private Profile/Bukan Teman
- Login
- Klik disini!
- Klik “Allow” untuk setuju dengan ketentuan dan kebijakanAkan keluar tampilan seperti dibawah: Paste kan target ID dan klik “Get Photos”
Selamat mencoba, mudah-mudahan masih bisa/belum di patch
sumber: dari berbagai sumber
Facebooknya Indonesia, The Indonesian Social Network.
Dapatkan banyak teman baru disini!, Dengan Aplikasi IM Chat dan Chat Room, Sharing Video/Mp3, Blog Dll
Daftar Disini!
Segera bergabung dengan FORUM kami, Daftar !
| Sela waktu dikantor, isi dengan berTrading Forex di Marketiva |
1. Membuka Account Gratis. Daftar Disini!
|
Related posts:
- Cara Mencari File Mp3, Video, Lirik di Facebook dan Mendownloadnya
- Facebook di Blok Kantor, Begini Cara Mengatasinya
- Cara Download Video di Facebook
- Download Mp3 Gratis ST12, Geisha, Zigaz, She, Seventeen, The Potters
- Cara Cashout Dari Program Bux.to
- Download Mp3 Gratis Nidji, Peterpan, Wali, Ungu, Saykoji, D’masive
- Download Mp3 Gratis Nidji, Dewa, Slank, Gigi, Padi, Godbless, Iwan Fals
- Download Mp3 Gratis Krisdayanti, Agnes Monica, Rosa, Ruth Sahanaya, Dewi Sandra, Dewi Dewi
- Aplikasi Facebook : PayPal WishList, Join dan Dapatkan Bonus $100 dari PayPal
- Trading Forex Dengan Modal Kecil, Dapatkan $5 Saat Registrasi!
Thread Programming in C, Java and Python with mutual exclusion/synchronization/locks
1. Thread Programming in C with and without mutual exclusion
Listing 1.1 threads.c (Threads without mutual exclusion)
1. /* threads.c
2. Example of multithreaded programming in C without mutual exclusion/locks
3. Author: S.Prasanna
4. */
5.
6. #include <pthread.h>
7. #include <stdio.h>
8.
9. int count = 0;
10.
11. void* run_thread()
12. {
13. pthread_t thread_id = pthread_self();
14. printf("Thread %u: Current value of count = %d\n", thread_id, count);
15. printf("Thread %u incrementing count ...\n");
16. count++;
17. sleep(1);
18. printf("Value of count after incremented by thread %u = %d\n", thread_id, count);
19. pthread_exit(NULL);
20. }
21.
22. int main (int argc, char *argv[])
23. {
24. pthread_t thread_array[4];
25. int i = 0, ret, thread_num = 4;
26.
27. for (i = 0; i < thread_num; i++) {
28. if ((ret = pthread_create(&thread_array[i], NULL, run_thread, NULL)) == -1) {
29. printf("Thread creation failed with return code: %d", ret);
30. exit(ret);
31. }
32. }
33. pthread_exit(NULL);
34. }
Thread 2: Current value of count = 0
Thread 2 incrementing count ...
Thread 3: Current value of count = 1
Thread 3 incrementing count ...
Thread 4: Current value of count = 2
Thread 4 incrementing count ...
Thread 5: Current value of count = 2
Thread 5 incrementing count ...
Value of count after incremented by thread 4 = 4
Value of count after incremented by thread 3 = 4
Value of count after incremented by thread 5 = 4
Value of count after incremented by thread 2 = 4
Explanation:
In the above code, we use Pthreads interface for implementing the thread functionality in C, although I won't be going through the Pthread methods here, the above code creates four threads (line 27 - 31) which invokes the function run_thread function whose return type is a pointer to void (line 11) where all threads increment the global count value (line 16), sleeps for a second and prints the value of count after its incremented by that thread (lines 11 - 20), since context switch occurs when threads sleep, the other threads increment the value by the time a thread sleeps and so on, as a result the threads couldn't print the value of count correctly after its incremented by them, this problem can be solved using mutual exclusion construct as shown below.
1. /* threads_lock.cOutput:
2. Example of multithreaded programming in C with mutual exclusion/locks
3. Author: S.Prasanna
4. */
5.
6. #include <pthread.h>
7. #include <stdio.h>
8.
9. int count = 0;
10. pthread_mutex_t thread_lock;
11.
12. void* run_thread()
13. {
14. pthread_mutex_lock(&thread_lock);
15. pthread_t thread_id = pthread_self();
16. printf("Thread %u: Current value of count = %d\n", thread_id, count);
17. printf("Thread %u incrementing count ...\n");
18. count++;
19. sleep(1);
20. printf("Value of count after incremented by thread %u = %d\n", thread_id, count);
21. pthread_mutex_unlock(&thread_lock);
22. pthread_exit(NULL);
23. }
24.
25. int main (int argc, char *argv[])
26. {
27. pthread_t thread_array[4];
28. int i = 0, ret, thread_num = 4;
29.
30. for (i = 0; i < thread_num; i++) {
31. if ((ret = pthread_create(&thread_array[i], NULL, run_thread, NULL)) == -1) {
32. printf("Thread creation failed with return code: %d", ret);
33. exit(ret);
34. }
35. }
36. pthread_exit(NULL);
37. }
38.
Thread 2: Current value of count = 0
Thread 2 incrementing count ...
Value of count after incremented by thread 2 = 1
Thread 5: Current value of count = 1
Thread 5 incrementing count ...
Value of count after incremented by thread 5 = 2
Thread 4: Current value of count = 2
Thread 4 incrementing count ...
Value of count after incremented by thread 4 = 3
Thread 3: Current value of count = 3
Thread 3 incrementing count ...
Value of count after incremented by thread 3 = 4
Explanation:
Listing 2.1 Counter.java (Threads without synchronization)
1. /*Output:
2. * An example of threads without lock (synchronized block)
3. * Author: S.Prasanna
4. *
5. */
6.
7. public class Counter implements Runnable {
8.
9. int count = 0;
10.
11. public Counter() {
12. }
13.
14. public void run() {
15. System.out.println(Thread.currentThread().getName() + ": " + "Current Value of count = " + count);
16. System.out.println(Thread.currentThread().getName() + " increments count....");
17. count ++;
18. try {
19. Thread.currentThread().sleep(1000);
20. } catch (InterruptedException e) {
21. System.out.println("Thread " + Thread.currentThread().getName() + "interrupted.");
22. }
23. System.out.println("Value of count after incremented by thread "
24. + Thread.currentThread().getName() + " = " + count);
25. }
26.
27. public static void main(String args[]) {
28. Counter c = new Counter();
29.
30. Thread t1 = new Thread(c);
31. Thread t2 = new Thread(c);
32. Thread t3 = new Thread(c);
33. Thread t4 = new Thread(c);
34.
35. t1.setName("Thread 1");
36. t2.setName("Thread 2");
37. t3.setName("Thread 3");
38. t4.setName("Thread 4");
39.
40. t1.start();
41. t2.start();
42. t3.start();
43. t4.start();
44.
45. try {
46. t1.join();
47. t2.join();
48. t3.join();
49. t4.join();
50. }
51. catch (InterruptedException e) {
52. System.out.println("Main thread Interrupted .....");
53. }
54.
55. System.out.println("Main thread exits.....");
56. }
57. }
58.
C:\>java Counter
Thread 1: Current Value of count = 0
Thread 1 increments count....
Thread 2: Current Value of count = 1
Thread 2 increments count....
Thread 3: Current Value of count = 2
Thread 3 increments count....
Thread 4: Current Value of count = 3
Thread 4 increments count....
Value of count after incremented by thread Thread 1 = 4
Value of count after incremented by thread Thread 2 = 4
Value of count after incremented by thread Thread 3 = 4
Value of count after incremented by thread Thread 4 = 4
Main thread exits.....
Explanation:
The main method creates four threads (lines 30 - 33) created by extending the Runnable interface which increments the Counter's instance variable count (line 17), sleeps for a second and prints the incremented value (lines 14 - 25), since context switch occurs when a thread sleeps, other threads increment the count value by the time a thread sleeps and when the sleeping threads resumes execution, it read a wrong count value, this can be fixed with the synchronized construct as seen in Listing 2.2.
1. /*Output:
2. * An example of threads without lock (synchronized block)
3. * Author: S.Prasanna
4. *
5. */
6.
7. public class Counter_locks implements Runnable {
8.
9. int count = 0;
10.
11. public Counter_locks() {
12. }
13.
14. public synchronized void run() {
15. System.out.println(Thread.currentThread().getName() + ": " + "Current Value of count = " + count);
16. System.out.println(Thread.currentThread().getName() + " increments count....");
17. count ++;
18. try {
19. Thread.currentThread().sleep(1000);
20. } catch (InterruptedException e) {
21. System.out.println("Thread " + Thread.currentThread().getName() + "interrupted.");
22. }
23. System.out.println("Value of count after incremented by thread "
24. + Thread.currentThread().getName() + " = " + count);
25. }
26.
27. public static void main(String args[]) {
28. Counter_locks c = new Counter_locks();
29.
30. Thread t1 = new Thread(c);
31. Thread t2 = new Thread(c);
32. Thread t3 = new Thread(c);
33. Thread t4 = new Thread(c);
34.
35. t1.setName("Thread 1");
36. t2.setName("Thread 2");
37. t3.setName("Thread 3");
38. t4.setName("Thread 4");
39.
40. t1.start();
41. t2.start();
42. t3.start();
43. t4.start();
44.
45. try {
46. t1.join();
47. t2.join();
48. t3.join();
49. t4.join();
50. }
51. catch (InterruptedException e) {
52. System.out.println("Main thread Interrupted .....");
53. }
54.
55. System.out.println("Main thread exits.....");
56. }
57. }
58.
C:\>java Counter_locks
Thread 1: Current Value of count = 0
Thread 1 increments count....
Value of count after incremented by thread Thread 1 = 1
Thread 4: Current Value of count = 1
Thread 4 increments count....
Value of count after incremented by thread Thread 4 = 2
Thread 3: Current Value of count = 2
Thread 3 increments count....
Value of count after incremented by thread Thread 3 = 3
Thread 2: Current Value of count = 3
Thread 2 increments count....
Value of count after incremented by thread Thread 2 = 4
Main thread exits.....
Explanation:
Listing 2.2 differs from Listing 2.1 in a single line, it synchronizes the run method (line 14) executed by threads to ensure that only a single thread can access the synchronized block at any point of time, therefore a thread runs through the synchronized block of code without context switching, resulting in printing the correct count value after it increments it.
1. #Output:
2. # Invoking multiple threads from python without locking mechanism
3. # pythreads.py
4. # Author: S.Prasanna
5. #
6.
7. import thread
8. import threading
9. import time
10.
11. def run_thread (threadname, sleeptime):
12. """This is the thread function to be invoked."""
13.
14. global threadcount, activethreads
15.
16. print "%s: Current value of threadcount %s" % (threadname, threadcount)
17. print "%s incrementing threadcount" % (threadname)
18. threadcount = threadcount + 1
19. time.sleep(sleeptime)
20. print "Value of threadcount after incremented by %s = %s" % (threadname, threadcount)
21. activethreads = activethreads - 1
22. print "%s exiting...." % (threadname)
23.
24. if __name__ == "__main__":
25.
26. threadcount=0
27. activethreads = 4
28.
29. thread.start_new_thread(run_thread, ("Thread1", 1))
30. thread.start_new_thread(run_thread, ("Thread2", 1))
31. thread.start_new_thread(run_thread, ("Thread3", 1))
32. thread.start_new_thread(run_thread, ("Thread4", 1))
33.
34. while activethreads > 0:
35. pass
36.
C:\>python pythreads.py
Thread1: Current value of threadcount 0
Thread1 incrementing threadcount
Thread2: Current value of threadcount 1
Thread2 incrementing threadcount
Thread3: Current value of threadcount 2
Thread3 incrementing threadcount
Thread4: Current value of threadcount 3
Thread4 incrementing threadcount
Value of threadcount after incremented by Thread1 = 4
Thread1 exiting....
Value of threadcount after incremented by Thread2 = 4
Thread2 exiting....
Value of threadcount after incremented by Thread3 = 4
Thread3 exiting....
Value of threadcount after incremented by Thread4 = 4
Thread4 exiting....
Explanation:
Thread programming python is quite simple to say the least, the main creates four threads using the thread module's start_new_thread() method (lines 29 - 32), each invokes the run_thread() (line 11) method which increments a shared variable count, sleeps for a second and prints the incremented value, since no lock mechanism is used ensure exclusive access, context switch occurs when the threads sleep as a result they read a wrong value upon resuming (after its incremented by other threads), the solution, Listing 3.2 with locks.
1. #
2. # Invoking multiple threads from python with locks
3. # pythreads_lock.py
4. # Author: S.Prasanna
5. #
6.
7. import thread
8. import threading
9. import time
10.
11. def run_thread (threadname, sleeptime):
12. """This is the thread function to be invoked."""
13.
14. global threadcount, activethreads, threadlock
15.
16. threadlock.acquire()
17.
18. print "%s: Current value of threadcount %s" % (threadname, threadcount)
19. print "%s incrementing threadcount" % (threadname)
20. threadcount = threadcount + 1
21. time.sleep(sleeptime)
22. print "Value of threadcount after incremented by %s = %s" % (threadname, threadcount)
23. activethreads = activethreads - 1
24. print "%s exiting...." % (threadname)
25.
26. threadlock.release()
27.
28. if __name__ == "__main__":
29.
30. threadcount=0
31. activethreads = 4
32. threadlock = thread.allocate_lock()
33.
34. thread.start_new_thread(run_thread, ("Thread1", 1))
35. thread.start_new_thread(run_thread, ("Thread2", 1))
36. thread.start_new_thread(run_thread, ("Thread3", 1))
37. thread.start_new_thread(run_thread, ("Thread4", 1))
38.
39. while activethreads > 0:
40. pass
41.
C:\>python pythreads_lock.py
Thread1: Current value of threadcount 0
Thread1 incrementing threadcount
Value of threadcount after incremented by Thread1 = 1
Thread1 exiting....
Thread2: Current value of threadcount 1
Thread2 incrementing threadcount
Value of threadcount after incremented by Thread2 = 2
Thread2 exiting....
Thread3: Current value of threadcount 2
Thread3 incrementing threadcount
Value of threadcount after incremented by Thread3 = 3
Thread3 exiting....
Thread4: Current value of threadcount 3
Thread4 incrementing threadcount
Value of threadcount after incremented by Thread4 = 4
Thread4 exiting....
Explanation:
The thread.allocate_lock() (line 32) method creates a lock object which a thread acquires using its acquire() method (line 16) before performing an atomic operation (lines 17 - 25), releases the lock using the release() method (line 26) so that other threads can access the mutually exclusive code block.
