關於部落格
  • 26394

    累積人氣

  • 0

    今日人氣

    0

    訂閱人氣

執行緒thread

/*編譯需加上thread函式庫 -D_REENTRANT -I/usr/include/nptl -L/usr/lib/nptl -lpthread 所以makefile改成 EXEC = ap OBJS = ap.o all: $(EXEC) $(EXEC): $(OBJS) $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) -lm -D_REENTRANT -I/usr/include/nptl -L/usr/lib/nptl -lpthread romfs: $(ROMFSINST) /bin/$(EXEC) clean: -rm -f $(EXEC) *.elf *.gdb *.o */ /*時間/日期管理實例*/ /*DataTest.c*/ //#include < time.h> #include #include #include #include #include //#include #include #include #include //#include #include #include #include #include #include #include #include #include #include #include //#include #include #include //#include "asm/arch/lib/lcd-creator.h" #include "asm/arch/lib/creator_s3c4510_lcd.h" #include "creator_lib.h" #include "creator_lib.c" void *thread_function(void *arg); char message[] = "Hello World"; int main() { int res; pthread_t a_thread; void *thread_result; res = pthread_create(&a_thread, NULL, thread_function, (void *)message); if (res != 0) { perror("Thread creation failed"); exit(EXIT_FAILURE); } printf("Waiting for thread to finish...n"); res = pthread_join(a_thread, &thread_result); if (res != 0) { perror("Thread join failed"); exit(EXIT_FAILURE); } printf("Thread joined, it returned %sn", (char *)thread_result); printf("Message is now %sn", message); exit(EXIT_SUCCESS); } void *thread_function(void *arg) { printf("thread_function is running. Argument was %sn", (char *)arg); sleep(3); strcpy(message, "Bye!"); pthread_exit("Thank you for the CPU time"); }
相簿設定
標籤設定
相簿狀態