Monday, June 16, 2008

MultiThreading

Hi all…

Gw dapet pengetahuan baru nih di dunia c & linux, there is “how to create multi threading application in linux using c”, itu judul bukunya (tapi belum gw buat heheee).

Introduce of multithreading, multithreading adalah cara pengaksesan yang mengijinkan beberapa thread (bisa disebut juga sebagai proses) terjadi dalam satu proses (applikasi), yang saling berbagi sumber daya, tapi dapat dijalankan secara independen.

Berikut adalah implementasi dari multithreading di linux menggunakan c:


#include
#include
#include /* yang di butuhin buat create thread */

/* funsi yang akan dijalankan oleh thread yang memanggilnya */
void *print_message_function( void *ptr );
main()
{

pthread_t thread1, thread2; /* deklarasi thread */
char *message1 = “Thread 1″; /* parameter yang di berikan ke thread */
char *message2 = “Thread 2″;

int iret1, iret2;

/* buat thread, dan setip thread akan menjalankan funsingnya masing - masing */
iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);

pthread_join( thread1, NULL);
pthread_join( thread2, NULL);


printf(”Thread 1 returns: %d\n”,iret1);
printf(”Thread 2 returns: %d\n”,iret2);

exit(0);

}

void *print_message_function( void *ptr )
{

char *message;

message = (char *) ptr;
printf(”%s \n”, message);

}

Nah lo, dasarnya simple kan b-) ,,,silahkan mencoba ya…. ;)

Read More...

Tuesday, January 29, 2008

Dream Theater › The Spirit Carries On

Hi all....
gw baru denger lagu yang sebenernya sih udah lama juga...
tapi buat gw ni lagu emang keren abis...
mungkin juga karna ni lagu mirip2 seperti apa yang gw alamin selama ini..
btw, kalian denger aja lagu dari dream theater judulnya the spririt caries on
liriknya ada dibawah ini :


Nicholas:
Where did we come from?
Why are we here?
Where do we go when we die?
What lies beyond
And what lay before?
Is anything certain in life?

They say, life is too short,
The here and the now
And youre only given one shot
But could there be more,
Have I lived before,
Or could this be all that weve got?

If I die tomorrow
Id be allright
Because I believe
That after were gone
The spirit carries on

I used to be frightened of dying
I used to think death was the end
But that was before
Im not scared anymore
I know that my soul will transcend

I may never find all the answers
I may never understand why
I may never prove
What I know to be true
But I know that I still have to try

If I die tomorrow
Id be allright
Because I believe
That after were gone
The spirit carries on

Victoria:
Move on, be brave
Dont weep at my grave
Because I am no longer here
But please never let
Your memory of me disappear

Nicholas:
Safe in the light that surrounds me
Free of the fear and the pain
My questioning mind
Has helped me to find
The meaning in my life again
Victorias real
I finally feel
At peace with the girl in my dreams
And now that Im here
Its perfectly clear
I found out what all of this means

If I die tomorrow
Id be allright
Because I believe
That after were gone
The spirit carries on

Read More...

Thursday, November 8, 2007

Encrypt and Decrypt Image - BMP

Hallow semua...
gw punya source code simple untuk encrypt ato decrypt file gambar (untuk kasus sekarang kita pake file gambar bitmap). Tampilanya seperti ini:

Encrypt bitmap

Decrypt bitmap

Code untuk encrypt/decrypt button seperti ini:

PROCEDURE TForm1.Button2Click(Sender: TObject);
VAR
i : INTEGER;
j : INTEGER;
RandomValue : BYTE;
rowIn : pByteArray;
rowOut : pByteArray;
ScanlineByteCount: INTEGER;
BitmapResult : TBitmap;
BEGIN
/*
BitmapOriginal : tipe dile TBitmap dan di inisialisasi pada saat open file
*/
IF Assigned(BitmapResult)
THEN BitmapResult.Free;

BitmapResult := TBitmap.Create;
BitmapResult.Width := BitmapOriginal.Width;
BitmapResult.Height := BitmapOriginal.Height;
BitmapResult.PixelFormat := BitmapOriginal.PixelFormat;

IF BitmapOriginal.PixelFormat IN [pf1bit, pf4bit, pf8bit]
THEN BitmapResult.Palette := CopyPalette(BitmapOriginal.Palette);

ScanlineByteCount := ABS(Integer(BitmapOriginal.Scanline[1]) -
Integer(BitmapOriginal.Scanline[0]));

RandSeed := 79997;

FOR j := 0 TO BitmapOriginal.Height-1 DO
BEGIN
RowIn := BitmapOriginal.Scanline[j];
RowOut := BitmapResult.Scanline[j];

FOR i := 0 TO ScanlineByteCount-1 DO
BEGIN
RandomValue := Random(256);
RowOut[i] := RowIn[i] XOR RandomValue
END
END;

Image1.Picture.Graphic := BitmapResult;
END;


Selamat mencoba ya...keep writing..:D

Read More...

Saturday, October 20, 2007

Windows API - Delphi

Memanfaatkan applikasi - applikasi bawaan dari windows merupakan hal yang sangat mudah dilakukan. Saat ini kita akan mencoba membuat applikasi sederhana menggunakan Borland Delphi 7, untuk memamnggil applikasi windows seperti notepad, calculator, dan paint.

Hal-hal yang perlu dilakukan untuk membuat applikasi sederhana tersebut adalah sebagai berikut:
1. Yang pasti kalian harus punnya borland delphi nya dulu ya... hahahaa
2. Buat project baru,
3. Buat 3 button, yang pertama button untuk panggil notepad, yang kedua untuk panggil calculator, dan yang ketiga adalah untuk panggil paint.
4. Kemudian masuk ke script (tekan F12)

5. Pada uses, tambahkan ShellApi
6. Pada Button notepad, tambahkan code berikut:
ShellExecute(Handle, 'open', 'c:\Windows\notepad.exe', nil, nil, SW_SHOWNORMAL);
7. Pada Button calculator, tambahkan code berikut:
ShellExecute(Handle, 'open', 'c:\Windows\system32\calculator.exe', nil, nil, SW_SHOWNORMAL) ;
8. Pada Button paint, tambahkan code berikut:
ShellExecute(Handle, 'open', 'c:\Windows\system32\mspaint.exe', nil, nil, SW_SHOWNORMAL) ;

Keterangan: kalo salah, berati exe file nya salah heee coba liat lagi aja di windowsnya...
Selamat mencoba...

Read More...