|
发表于 2004-12-3 23:37:31
|
显示全部楼层
你那个for循环一点延时都没有,cpu资源都被它用光了,不死才怪。
[code:1]
#include<gtk/gtk.h>
#include<pthread.h>
int print()
{
int i=0;
for(;;)
{
printf("Hello World+%d\n",i);
i++;
sleep(1);
}
}
void init()
{
pthread_t thread;
if(pthread_create(&thread,NULL,(void*)print,NULL))
printf("not enouth resources for create a thread\n");
// if(pthread_join(thread,NULL))printf("error to join the thread!\n");
}
GtkWidget *
create_window()
{
GtkWidget *button;
GtkWidget *window;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
gtk_window_set_default_size(GTK_WINDOW(window),500,100);
gtk_container_set_border_width(GTK_CONTAINER(window),40);
button=gtk_button_new_with_label("printf hello world");
gtk_signal_connect_after(GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC (init), NULL);
gtk_container_add(GTK_CONTAINER(window),button);
return window;
}
int main(int argc,char*argv[])
{
gtk_init(&argc,&argv);
GtkWidget *window1=create_window();
pthread_t window_thread;
gtk_widget_show_all(window1);
gtk_main();
return FALSE;
}
[/code:1] |
|