| 180 | pthread_exit(NULL); |
| 181 | } |
| 182 | static int thread_create( |
| 183 | thread_t *thread, void *task, void *parameter, void *pexit) |
| 184 | { |
| 185 | int res; |
| 186 | pthread_attr_t attr; |
| 187 | |
| 188 | thread->task = task; |
| 189 | thread->para = parameter; |
| 190 | thread->exit = pexit; |
| 191 | |
| 192 | if (sem_init(&thread->sem, 0, 0) != 0) |
| 193 | { |
| 194 | printf("init thread->sem failed, exit \n"); |
| 195 | exit(EXIT_FAILURE); |
| 196 | } |
| 197 | /* No need to join the threads. */ |
| 198 | pthread_attr_init(&attr); |
| 199 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 200 | |
| 201 | /* create a posix thread */ |
| 202 | res = pthread_create(&thread->pthread, &attr, &thread_run, (void *)thread); |
| 203 | if (res) |
| 204 | { |
| 205 | printf("pthread create faild, <%d>\n", res); |
| 206 | exit(EXIT_FAILURE); |
| 207 | } |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /* resume the thread */ |
| 213 | static int thread_resume(thread_t *thread) |
no test coverage detected