c - Thread function timing -
when create thread automatically start thread function that's in parameter?
i'm using
iret1 = pthread_create(&client[i++].tid, null, thread_function, null); printf("thread created"); //for testing purposes in thread function have print statement @ top. ex:
void *thread_function(void *arg){ printf("entered thread function"); ... } instead of printing entered thread function prints thread created right after
and doesn't print entered thread function until start thread, there reason this?
you need @ least add newline \n @ end of every printf(3) format function, , call fflush(3), e.g. add call fflush(null); after each of 2 printf ...
don't forget <stdio.h> functions buffered. see setvbuf(3) function , man page.
the reason why output not printed want is staying in buffer of stdout.
and have no guarantee on output. individual characters might perhaps intermixed. read unlocked_stdio(3) , flockfile(3) details.
you may want read (several times) pthread tutorial...
ps consider using directly write(2) syscall (without using <stdio.h> function).
Comments
Post a Comment