[DragonFlyBSD - Bug #3203] (New) Don't assume pthread_t is a pointer

bugtracker-admin at leaf.dragonflybsd.org bugtracker-admin at leaf.dragonflybsd.org
Fri Aug 30 05:59:12 PDT 2019


Issue #3203 has been reported by tkusumi.

----------------------------------------
Bug #3203: Don't assume pthread_t is a pointer
http://bugs.dragonflybsd.org/issues/3203

* Author: tkusumi
* Status: New
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
A pthread_t variable doesn't need to be initialized with NULL prior to calling pthread_create(3).
This also isn't portable since pthread_t is an opaque type (i.e. may not be a pointer, and in fact it's not on Linux/glibc).

# grep "thread = NULL" sbin/hammer2 -rI
sbin/hammer2/subs.c:    pthread_t thread = NULL;
sbin/hammer2/cmd_service.c:     thread = NULL;
sbin/hammer2/cmd_service.c:     thread = NULL;
sbin/hammer2/cmd_service.c:             thread = NULL;
sbin/hammer2/cmd_service.c:                             conf->thread = NULL;
sbin/hammer2/cmd_service.c:             conf->iocom_thread = NULL;
sbin/hammer2/cmd_service.c:                                     thread = NULL;


It looks like above exists for this conditional below.
If this could be rewritten without testing pthread_t itself (it shouldn't be too), NULL initialization could be removed.

 369                 if (conf->thread == NULL) {
 370                         fprintf(stderr, "VOLCONF THREAD STARTED\n");
 371                         pthread_cond_init(&conf->cond, NULL);
 372                         pthread_create(&conf->thread, NULL,
 373                                        hammer2_volconf_thread, (void *)conf);
 374                 }



-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account



More information about the Bugs mailing list