| void checked_write(int fd, const void *buf, size_t count) |
| ssize_t rc = write(fd, buf, count); |
| void *thread1_func(void *arg) |
| snprintf(buf, sizeof(buf), "thread1: %d %s\n", i, (char *)arg); |
| checked_write(1, buf, strlen(buf)); |
| void *thread2_func(void *arg) |
| snprintf(buf, sizeof(buf), "thread2: %d %s\n", i, (char *)arg); |
| checked_write(1, buf, strlen(buf)); |
| pthread_create(&tid1, NULL, thread1_func, "hello1"); |
| pthread_create(&tid2, NULL, thread2_func, "hello2"); |
| pthread_join(tid1, NULL); |
| pthread_join(tid2, NULL); |
| printf("End of pthread test.\n"); |
| int main(int argc, char **argv) |