pthread_t definition

本文探讨了Chromium项目中base库的线程管理模块,特别是针对不同平台(如POSIX和Windows)下线程数据结构的定义差异进行了讨论。文章分析了pthread_t类型在不同系统中的具体实现,并指出了在代码中初始化该类型变量时可能遇到的可移植性问题。

最近在看google的chromium的代码,觉得其基础库base中的对于与平台有关的线程的数据结构的定义与其代码中的注释部分不匹配。

 

 

 

注释明确说明 phtread_t在标准中有被定义为一个结构体的可能性,但其在实际代码中仍然出现了:

 

 

#include <pthread.h>

typedef pthread_t PlatformThreadHandle;

const PlatformThreadHandle kNullThreadHandle = 0;

 

 

显然此写法肯定不是个错误,否则chromium在posix系统上就编译不过去了。

 

为此专门search了一下pthread_t的定义,发现很真是有多种定义方法,

 

在linux的实现中pthread_t被定义为 "unsigned long int", 参见如下详细说明:

 

With LinuxThreads (the default Pthreads library on 2.4 kernel), the
pthread_t was in fact related to an index of an internal table. With
NPTL, the pthread_t holds the memory address of a structure that
describes the thread properties.

 

在Windows中pthread_t的确被定义为一个结构体:

 

 

 

从而导致如下代码不具有可移植性:

 

pthread_t tid;

.....

tid = (pthread_t)0;

 

正确的实现应该是用memset()来将其初始化为0,尽管在有的系统的实现中,将pthread_t的变量初始化为0也未必是一个正确的选择。

 

 

 

sr/include/time.h:371:27: error: unknown type name ‘timer_t’ extern int timer_settime (timer_t __timerid, int __flags, ^ /usr/include/time.h:376:27: error: unknown type name ‘timer_t’ extern int timer_gettime (timer_t __timerid, struct itimerspec *__value) ^ /usr/include/time.h:380:30: error: unknown type name ‘timer_t’ extern int timer_getoverrun (timer_t __timerid) __THROW; ^ In file included from /usr/include/pthread.h:26:0, from multi_threaded.c:2: /usr/include/bits/pthreadtypes.h:60:27: error: storage class specified for parameter ‘pthread_t’ typedef unsigned long int pthread_t; ^ /usr/include/bits/pthreadtypes.h:69:30: error: storage class specified for parameter ‘pthread_attr_t’ typedef union pthread_attr_t pthread_attr_t; ^ /usr/include/bits/pthreadtypes.h:79:3: error: storage class specified for parameter ‘__pthread_list_t’ } __pthread_list_t; ^ /usr/include/bits/pthreadtypes.h:106:5: error: expected specifier-qualifier-list before ‘__pthread_list_t’ __pthread_list_t __list; ^ /usr/include/bits/pthreadtypes.h:128:3: error: storage class specified for parameter ‘pthread_mutex_t’ } pthread_mutex_t; ^ /usr/include/bits/pthreadtypes.h:134:3: error: storage class specified for parameter ‘pthread_mutexattr_t’ } pthread_mutexattr_t; ^ /usr/include/bits/pthreadtypes.h:154:3: error: storage class specified for parameter ‘pthread_cond_t’ } pthread_cond_t; ^ /usr/include/bits/pthreadtypes.h:160:3: error: storage class specified for parameter ‘pthread_condattr_t’ } pthread_condattr_t; ^ /usr/include/bits/pthreadtypes.h:164:22: error: storage class specified for parameter ‘pthread_key_t’ typedef unsigned int pthread_key_t; ^ /usr/include/bits/pthreadtypes.h:168:13: error: storage class specified for parameter ‘pthread_once_t’ typedef int pthread_once_t; ^ /usr/include/bits/pthreadtypes.h:214:3: error: storage class specified for parameter ‘pthread_rwlock_t’ } pthread_rwlock_t; ^ /usr/include/bits/pthreadtypes.h:220:3: error: storage class specified for parameter ‘pthread_rwlockattr_t’ } pthread_rwlockattr_t; ^ /usr/include/bits/pthreadtypes.h:226:22: error: storage class specified for parameter ‘pthread_spinlock_t’ typedef volatile int pthread_spinlock_t; ^ /usr/include/bits/pthreadtypes.h:235:3: error: storage class specified for parameter ‘pthread_barrier_t’ } pthread_barrier_t; ^ /usr/include/bits/pthreadtypes.h:241:3: error: storage class specified for parameter ‘pthread_barrierattr_t’ } pthread_barrierattr_t; ^ In file included from /usr/include/pthread.h:27:0, from multi_threaded.c:2: /usr/include/bits/setjmp.h:31:18: error: storage class specified for parameter ‘__jmp_buf’ typedef long int __jmp_buf[8]; ^ In file included from multi_threaded.c:2:0: /usr/include/pthread.h:235:28: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_create (pthread_t *__restrict __newthread, ^ /usr/include/pthread.h:236:28: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token const pthread_attr_t *__restrict __attr, ^ /usr/include/pthread.h:244:13: error: storage class specified for parameter ‘pthread_exit’ extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__)); ^ /usr/include/pthread.h:252:26: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_join (pthread_t __th, void **__thread_return); ^ /usr/include/pthread.h:273:28: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_detach (pthread_t __th) __THROW; ^ /usr/include/pthread.h:277:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pthread_self’ extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__)); ^ /usr/include/pthread.h:280:27: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) ^ /usr/include/pthread.h:280:48: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) ^ /usr/include/pthread.h:289:31: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1)); ^ /usr/include/pthread.h:292:34: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_destroy (pthread_attr_t *__attr) ^ /usr/include/pthread.h:296:62: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr, ^ /usr/include/pthread.h:301:41: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setdetachstate (pthread_attr_t *__attr, ^ /usr/include/pthread.h:307:60: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getguardsize (const pthread_attr_t *__attr, ^ /usr/include/pthread.h:312:39: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setguardsize (pthread_attr_t *__attr, ^ /usr/include/pthread.h:313:11: error: expected declaration specifiers or ‘...’ before ‘size_t’ size_t __guardsize) ^ /usr/include/pthread.h:318:61: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr, ^ /usr/include/pthread.h:323:40: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr, ^ /usr/include/pthread.h:328:62: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict ^ /usr/include/pthread.h:333:41: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy) ^ /usr/include/pthread.h:337:63: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict ^ /usr/include/pthread.h:342:42: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setinheritsched (pthread_attr_t *__attr, ^ /usr/include/pthread.h:348:56: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr, ^ /usr/include/pthread.h:353:35: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope) ^ /usr/include/pthread.h:357:60: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict ^ /usr/include/pthread.h:365:39: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setstackaddr (pthread_attr_t *__attr, ^ /usr/include/pthread.h:370:60: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict ^ /usr/include/pthread.h:377:39: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setstacksize (pthread_attr_t *__attr, ^ /usr/include/pthread.h:378:11: error: expected declaration specifiers or ‘...’ before ‘size_t’ size_t __stacksize) ^ /usr/include/pthread.h:383:56: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr, ^ /usr/include/pthread.h:391:35: error: expected declaration specifiers or ‘...’ before ‘pthread_attr_t’ extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, ^ /usr/include/pthread.h:392:7: error: expected declaration specifiers or ‘...’ before ‘size_t’ size_t __stacksize) __THROW __nonnull ((1)); ^ /usr/include/pthread.h:423:35: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_setschedparam (pthread_t __target_thread, int __policy, ^ /usr/include/pthread.h:428:35: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_getschedparam (pthread_t __target_thread, ^ /usr/include/pthread.h:434:34: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_setschedprio (pthread_t __target_thread, int __prio) ^ /usr/include/pthread.h:488:26: error: expected declaration specifiers or ‘...’ before ‘pthread_once_t’ extern int pthread_once (pthread_once_t *__once_control, ^ /usr/include/pthread.h:500:12: error: storage class specified for parameter ‘pthread_setcancelstate’ extern int pthread_setcancelstate (int __state, int *__oldstate); ^ /usr/include/pthread.h:504:12: error: storage class specified for parameter ‘pthread_setcanceltype’ extern int pthread_setcanceltype (int __type, int *__oldtype); ^ /usr/include/pthread.h:507:28: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_cancel (pthread_t __th); ^ /usr/include/pthread.h:512:13: error: storage class specified for parameter ‘pthread_testcancel’ extern void pthread_testcancel (void); ^ /usr/include/pthread.h:521:5: error: expected specifier-qualifier-list before ‘__jmp_buf’ __jmp_buf __cancel_jmp_buf; ^ /usr/include/pthread.h:525:3: error: storage class specified for parameter ‘__pthread_unwind_buf_t’ } __pthread_unwind_buf_t __attribute__ ((__aligned__)); ^ /usr/include/pthread.h:525:3: error: alignment may not be specified for ‘__pthread_unwind_buf_t’ /usr/include/pthread.h:674:40: error: expected declaration specifiers or ‘...’ before ‘__pthread_unwind_buf_t’ extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) ^ /usr/include/pthread.h:686:42: error: expected declaration specifiers or ‘...’ before ‘__pthread_unwind_buf_t’ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) ^ /usr/include/pthread.h:727:36: error: expected declaration specifiers or ‘...’ before ‘__pthread_unwind_buf_t’ extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) ^ /usr/include/pthread.h:737:12: error: storage class specified for parameter ‘__sigsetjmp’ extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL; ^ /usr/include/pthread.h:743:32: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_init (pthread_mutex_t *__mutex, ^ /usr/include/pthread.h:744:37: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token const pthread_mutexattr_t *__mutexattr) ^ /usr/include/pthread.h:748:35: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) ^ /usr/include/pthread.h:752:35: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) ^ /usr/include/pthread.h:756:32: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_lock (pthread_mutex_t *__mutex) ^ /usr/include/pthread.h:761:37: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, ^ /usr/include/pthread.h:767:34: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) ^ /usr/include/pthread.h:772:64: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_mutex_getprioceiling (const pthread_mutex_t * ^ /usr/include/pthread.h:779:42: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, ^ /usr/include/pthread.h:787:38: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ extern int pthread_mutex_consistent (pthread_mutex_t *__mutex) ^ /usr/include/pthread.h:800:36: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) ^ /usr/include/pthread.h:804:39: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) ^ /usr/include/pthread.h:808:68: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t * ^ /usr/include/pthread.h:814:42: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr, ^ /usr/include/pthread.h:820:65: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict ^ /usr/include/pthread.h:827:39: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) ^ /usr/include/pthread.h:832:69: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t * ^ /usr/include/pthread.h:839:43: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, ^ /usr/include/pthread.h:844:72: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t * ^ /usr/include/pthread.h:850:46: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr, ^ /usr/include/pthread.h:856:67: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr, ^ /usr/include/pthread.h:866:41: error: expected declaration specifiers or ‘...’ before ‘pthread_mutexattr_t’ extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr, ^ /usr/include/pthread.h:882:33: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, ^ /usr/include/pthread.h:883:32: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token const pthread_rwlockattr_t *__restrict ^ /usr/include/pthread.h:887:36: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) ^ /usr/include/pthread.h:891:35: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) ^ /usr/include/pthread.h:895:38: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) ^ /usr/include/pthread.h:900:40: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, ^ /usr/include/pthread.h:906:35: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) ^ /usr/include/pthread.h:910:38: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) ^ /usr/include/pthread.h:915:40: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, ^ /usr/include/pthread.h:921:35: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlock_t’ extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) ^ /usr/include/pthread.h:928:37: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlockattr_t’ extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) ^ /usr/include/pthread.h:932:40: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlockattr_t’ extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) ^ /usr/include/pthread.h:936:70: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * ^ /usr/include/pthread.h:942:43: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlockattr_t’ extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr, ^ /usr/include/pthread.h:947:70: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t * ^ /usr/include/pthread.h:953:43: error: expected declaration specifiers or ‘...’ before ‘pthread_rwlockattr_t’ extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, ^ /usr/include/pthread.h:962:31: error: expected declaration specifiers or ‘...’ before ‘pthread_cond_t’ extern int pthread_cond_init (pthread_cond_t *__restrict __cond, ^ /usr/include/pthread.h:963:35: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token const pthread_condattr_t *__restrict __cond_attr) ^ /usr/include/pthread.h:967:34: error: expected declaration specifiers or ‘...’ before ‘pthread_cond_t’ extern int pthread_cond_destroy (pthread_cond_t *__cond) ^ /usr/include/pthread.h:971:33: error: expected declaration specifiers or ‘...’ before ‘pthread_cond_t’ extern int pthread_cond_signal (pthread_cond_t *__cond) ^ /usr/include/pthread.h:975:36: error: expected declaration specifiers or ‘...’ before ‘pthread_cond_t’ extern int pthread_cond_broadcast (pthread_cond_t *__cond) ^ /usr/include/pthread.h:983:31: error: expected declaration specifiers or ‘...’ before ‘pthread_cond_t’ extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, ^ /usr/include/pthread.h:984:10: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ pthread_mutex_t *__restrict __mutex) ^ /usr/include/pthread.h:994:36: error: expected declaration specifiers or ‘...’ before ‘pthread_cond_t’ extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, ^ /usr/include/pthread.h:995:8: error: expected declaration specifiers or ‘...’ before ‘pthread_mutex_t’ pthread_mutex_t *__restrict __mutex, ^ /usr/include/pthread.h:1002:35: error: expected declaration specifiers or ‘...’ before ‘pthread_condattr_t’ extern int pthread_condattr_init (pthread_condattr_t *__attr) ^ /usr/include/pthread.h:1006:38: error: expected declaration specifiers or ‘...’ before ‘pthread_condattr_t’ extern int pthread_condattr_destroy (pthread_condattr_t *__attr) ^ /usr/include/pthread.h:1010:66: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_condattr_getpshared (const pthread_condattr_t * ^ /usr/include/pthread.h:1016:41: error: expected declaration specifiers or ‘...’ before ‘pthread_condattr_t’ extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, ^ /usr/include/pthread.h:1021:64: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_condattr_getclock (const pthread_condattr_t * ^ /usr/include/pthread.h:1027:39: error: expected declaration specifiers or ‘...’ before ‘pthread_condattr_t’ extern int pthread_condattr_setclock (pthread_condattr_t *__attr, ^ /usr/include/pthread.h:1028:11: error: expected declaration specifiers or ‘...’ before ‘__clockid_t’ __clockid_t __clock_id) ^ /usr/include/pthread.h:1038:31: error: expected declaration specifiers or ‘...’ before ‘pthread_spinlock_t’ extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) ^ /usr/include/pthread.h:1042:34: error: expected declaration specifiers or ‘...’ before ‘pthread_spinlock_t’ extern int pthread_spin_destroy (pthread_spinlock_t *__lock) ^ /usr/include/pthread.h:1046:31: error: expected declaration specifiers or ‘...’ before ‘pthread_spinlock_t’ extern int pthread_spin_lock (pthread_spinlock_t *__lock) ^ /usr/include/pthread.h:1050:34: error: expected declaration specifiers or ‘...’ before ‘pthread_spinlock_t’ extern int pthread_spin_trylock (pthread_spinlock_t *__lock) ^ /usr/include/pthread.h:1054:33: error: expected declaration specifiers or ‘...’ before ‘pthread_spinlock_t’ extern int pthread_spin_unlock (pthread_spinlock_t *__lock) ^ /usr/include/pthread.h:1062:34: error: expected declaration specifiers or ‘...’ before ‘pthread_barrier_t’ extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier, ^ /usr/include/pthread.h:1063:34: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token const pthread_barrierattr_t *__restrict ^ /usr/include/pthread.h:1068:37: error: expected declaration specifiers or ‘...’ before ‘pthread_barrier_t’ extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) ^ /usr/include/pthread.h:1072:34: error: expected declaration specifiers or ‘...’ before ‘pthread_barrier_t’ extern int pthread_barrier_wait (pthread_barrier_t *__barrier) ^ /usr/include/pthread.h:1077:38: error: expected declaration specifiers or ‘...’ before ‘pthread_barrierattr_t’ extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) ^ /usr/include/pthread.h:1081:41: error: expected declaration specifiers or ‘...’ before ‘pthread_barrierattr_t’ extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) ^ /usr/include/pthread.h:1085:72: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t * ^ /usr/include/pthread.h:1091:44: error: expected declaration specifiers or ‘...’ before ‘pthread_barrierattr_t’ extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, ^ /usr/include/pthread.h:1105:32: error: expected declaration specifiers or ‘...’ before ‘pthread_key_t’ extern int pthread_key_create (pthread_key_t *__key, ^ /usr/include/pthread.h:1110:32: error: expected declaration specifiers or ‘...’ before ‘pthread_key_t’ extern int pthread_key_delete (pthread_key_t __key) __THROW; ^ /usr/include/pthread.h:1113:35: error: expected declaration specifiers or ‘...’ before ‘pthread_key_t’ extern void *pthread_getspecific (pthread_key_t __key) __THROW; ^ /usr/include/pthread.h:1116:33: error: expected declaration specifiers or ‘...’ before ‘pthread_key_t’ extern int pthread_setspecific (pthread_key_t __key, ^ /usr/include/pthread.h:1122:35: error: expected declaration specifiers or ‘...’ before ‘pthread_t’ extern int pthread_getcpuclockid (pthread_t __thread_id, ^ /usr/include/pthread.h:1123:7: error: expected declaration specifiers or ‘...’ before ‘__clockid_t’ __clockid_t *__clock_id) ^ /usr/include/pthread.h:1139:12: error: storage class specified for parameter ‘pthread_atfork’ extern int pthread_atfork (void (*__prepare) (void), ^ multi_threaded.c:5:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token int create_socket() { ^ multi_threaded.c:18:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token void bind_socket(int sockfd) { ^ multi_threaded.c:33:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token const char* get_content_type(const char* path) { ^ multi_threaded.c:50:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token int is_path_safe(const char* path) { ^ multi_threaded.c:55:40: error: unknown type name ‘http_status_t’ void send_http_response(int client_fd, http_status_t status, ^ multi_threaded.c:56:51: error: unknown type name ‘off_t’ const char* content_type, off_t content_length) { ^ multi_threaded.c:79:41: error: unknown type name ‘http_status_t’ void send_error_response(int client_fd, http_status_t status) { ^ multi_threaded.c:111:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token void* handle_client(void* arg) { ^ multi_threaded.c:182:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token int main() { ^ In file included from web_server.h:3:0, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from web_server.h:2, from multi_threaded.c:1: /usr/include/signal.h:403:12: error: old-style parameter declarations in prototyped function definition extern int __libc_current_sigrtmin (void) __THROW; ^ multi_threaded.c:218:1: error: expected ‘{’ at end of input } ^ multi_threaded.c:218:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ makefile:13: recipe for target 'threaded_server' failed make: *** [threaded_server] Error 1 出现一大堆报错
08-08
编译: selfcheck.c gcc -Wall -Wextra -std=c99 -pthread -g -O2 -I. -c selfcheck.c -o selfcheck.o In file included from selfcheck.c:43: cloud.h:29: warning: "__USE_XOPEN2K" redefined 29 | #define __USE_XOPEN2K // Enable X/Open extensions for pthread_rwlock_t | In file included from /usr/include/pthread.h:21, from selfcheck.c:35: /usr/include/features.h:357: note: this is the location of the previous definition 357 | # define __USE_XOPEN2K 1 | 编译: motor.c gcc -Wall -Wextra -std=c99 -pthread -g -O2 -I. -c motor.c -o motor.o In file included from main.h:40, from motor.c:31: cloud.h:177:5: error: unknown type name ‘pthread_rwlock_t’ 177 | pthread_rwlock_t status_rwlock; // 状态读写锁 | ^~~~~~~~~~~~~~~~ cloud.h:197:8: error: unknown type name ‘pthread_rwlock_t’ 197 | extern pthread_rwlock_t g_cmd_rwlock; | ^~~~~~~~~~~~~~~~ cloud.h:201:8: error: unknown type name ‘pthread_rwlock_t’ 201 | extern pthread_rwlock_t g_cloud_data_rwlock; | ^~~~~~~~~~~~~~~~ In file included from motor.c:31: main.h:148:8: error: unknown type name ‘pthread_rwlock_t’ 148 | extern pthread_rwlock_t g_data_rwlock; | ^~~~~~~~~~~~~~~~ main.h:151:8: error: unknown type name ‘pthread_rwlock_t’ 151 | extern pthread_rwlock_t g_cmd_rwlock; | ^~~~~~~~~~~~~~~~ main.h:160:8: error: unknown type name ‘pthread_rwlock_t’ 160 | extern pthread_rwlock_t g_selfcheck_rwlock; | ^~~~~~~~~~~~~~~~ main.h:170:8: error: unknown type name ‘pthread_rwlock_t’ 170 | extern pthread_rwlock_t g_cloud_rwlock; | ^~~~~~~~~~~~~~~~ motor.c: In function ‘wait_for_motor_completion’: motor.c:648:9: warning: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration] 648 | usleep(50000); // 50ms | ^~~~~~ | sleep motor.c: In function ‘emergency_stop_all_motors’: motor.c:884:13: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result] 884 | write(motor->uart_fd, emergency_cmd, sizeof(emergency_cmd)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ At top level: motor.c:998:20: warning: ‘get_motor_error_string’ defined but not used [-Wunused-function] 998 | static const char* get_motor_error_string(motor_error_code_t error) { | ^~~~~~~~~~~~~~~~~~~~~~ motor.c:981:20: warning: ‘get_motor_state_string’ defined but not used [-Wunused-function] 981 | static const char* get_motor_state_string(motor_state_t state) { | ^~~~~~~~~~~~~~~~~~~~~~ make: *** [Makefile:36: motor.o] Error 1 cat@lubancat:~/work/mushroom1$
10-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值