I caught a bug in my program. it was a non thread-safe function in json-c library. I knew there were some non thred-safe functions, but did not expect that json to string serializer could be non thread-safe and I did not wrap it in mutex locks.
the segfault problem is solved and it was not in PostgreSQL where it seemed to be. such uncertain bugs sometimes happen.
but now the question is to write a thread-safe version of json-c. I cannot tolerate so many locks for every parsing-printing operation. I could not find thread-safe json library and looks like I have to write it myself. well, not from the scratch, but taking json-c as a base, I think.