MyAlbum   Pet
DirectX   openGL   Java   C/C++   STL   C#   Python   Window   ActiveX   SE & Refactoring   Game   Unicode   googleDesktop   Network   Database   Web   php   asp   asp.net   Library   QT   wxWidget   Something to read  
ToDo
zelon's WebAlbum
Google Tools
Google Naver map
ToRearrange
OpenOffice.org
Eclipse
Check W3 validator
GTK Programming
e i R f
Anonymous

Contents

1 필요한 패키지들
2 컴파일 설정
3 간단한 설명
4 예제

1 필요한 패키지들 #


yum install 로 다음과 같은 것들을 설치한다.

  • glib2-devel
  • gtk2-devel

  • 2 컴파일 설정 #


    CC = gcc
    
    CFLAGS = -Wall -g -O2 `pkg-config --cflags gtk+-2.0 gthread-2.0`
    
    all: simple-list
    
    simple-list: main.o
            gcc -o test main.o `pkg-config --libs gtk+-2.0 gthread-2.0`
    
    clean:
            rm -f *.o simple-list *.c~ *.h~ 2>/dev/null
    
    

    3 간단한 설명 #


    gtk library 는 포팅을 위해서 c type 들을 래핑한 변수들을 이용한다.

    4 예제 #


    GThreadPool 을 사용하는 간단한 예제

    
    
    #define G_THREADS_ENABLED
    
    #include <gtk/gtk.h>
    #include <glib.h>
    #include <stdio.h>
    #include <assert.h>
    #include <time.h>
    #include <stdlib.h>
    #include <pthread.h>
    
    void threadPool(gpointer data, gpointer user_data);
    
    typedef struct _UserData
    {
    	int iIndex;
    	int iData;
    } UserData;
    
    int main()
    {
    	srand(time(NULL));
    	g_thread_init(NULL);
    	UserData commonData;
    	commonData.iIndex = 4141;
    	commonData.iData = 9153;
    
    	GError * error;
    
    	GThreadPool * tp = g_thread_pool_new(threadPool, &commonData, 5, TRUE, &error);
    
    	assert(tp);
    	if ( tp )
    	{
    		g_print("GThreadPool is initializedn");
    	}
    
    	UserData aData;
    	aData.iIndex = rand();
    	aData.iData = rand();
    	
    	int i = 0;
    	for ( i = 0; i < 100; ++i)
    	{
    		g_thread_pool_push(tp, &aData, &error);
    		aData.iIndex = rand();
    		aData.iData = rand();
    
    	}
    
    	g_thread_pool_free(tp, FALSE, TRUE);
    	g_print("All Thread pool is ended and freed.n");
    
    	return 0;
    }
    
    void threadPool(gpointer data, gpointer user_data)
    {
    	UserData * p = data;
    
    	g_print("iIndex : %d, iData : %dn", p->iIndex, p->iData);
    }