contributed by <janetwei
>
參考 TempoJiJi 的共筆,測試程式效能以及正確性
列出參考的共筆時,要一併提及人名或代稱。 jserv
size of entry : 24 bytes
execution time of append() : 0.005272 sec
execution time of findName() : 0.004161 sec
這是預期做出的結果
append() findName() 0.005272 0.004161
append() findName() 0.005856 0.003475
但是做出來的output卻不是這樣,少了兩個值
size of entry : 24 bytes
execution time of append() : 0.005856 sec
execution time of findName() : 0.003475 sec
避免用圖片來表示程式的文字訊息,請改正 jserv
已改正孜昀
source
mutex:指的是一組用來控制共享資源存取的一組函數
因為在thread的情況下,所有的資源以及變數是共用的,因此必須對大家都可以存取的變數加以控制
因此區分為以下幾個function:
pthread_cond_t:use for condition variables
pthread_mutex_t:use for mutex
pthread_cond_wait():
It is used to block on a condition variable. They are called with mutex locked by the calling thread or undefined behaviour will result.
These functions atomically release mutex and cause the calling thread to block on the condition variable.
pthread_attr_setdetachstate():
The detachstate attribute controls whether the thread is created in a detached state.
pthread_create():
It is used to create a new thread, with attributes specified by attr, within a process. If attr is NULL, the default attributes are used.
pthread_join():
This function suspends execution of the calling thread until the target thread terminates, unless the target thread has already terminated.
On return from a successful pthread_join() call with a non-NULL value_ptr argument, the value passed to pthread_exit() by the terminating thread is made available in the location referenced by value_ptr.
檔案處理參考
#include <stdio.h>
FILE *fopen( char *filename,char *mode);
int fclose(FILE *stream);
char *fgets(char *s, int n, FILE *stream);
size_t fwrite( void *ptr, size_t size, size_t nobj, FILE *stream)
strcpy(wbuf, rbuf);
#include <string.h>
void * memset ( void * ptr, int value, size_t num )
#include <sys/types.h>
off_t fsize(char *path);
#include <sys/stat.h>
struct stat(char filename,struct stat *buf)
struct stat
:是用來儲存檔案資訊的資料結構,包含檔案大小、類型、修改日期等資訊程式問題:
1.wbuf是由system call malloc()
配置的,結束時卻沒有free
->memory leak
2.當輸入字串字數等於pad時,資料卻不會copy過去,這造成些資料的遺失
參考LanKuDot的共筆
$astyle --style=kr --indent=spaces=4 --indent-switches --suffix=none *.[ch]
確認排版一致
1.file_align(DICT_FILE, ALIGN_FILE, MAX_LAST_NAME_SIZE);
將DICT_FILE轉成ALIGN_FILE