diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 80514f8d1b327fde97cdfd14ee5e550cce085da0..58c5f6e81dfb34e53a3ad1b5e3521c9e21482ff4 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -1080,7 +1080,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
 	if ((conf->recording == MEETME_RECORD_OFF) && ((confflags & CONFFLAG_RECORDCONF) || (conf->lchan))) {
 		pthread_attr_init(&conf->attr);
 		pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
-		ast_pthread_create(&conf->recordthread, &conf->attr, recordthread, conf);
+		ast_pthread_create_background(&conf->recordthread, &conf->attr, recordthread, conf);
 	}
 
 	time(&user->jointime);
diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
index 1530920b102e9ae3521302fdd15c6fa4a6b8c7d9..1171fc89e17adaee41abac3acc75bd2181aaf229 100644
--- a/apps/app_mixmonitor.c
+++ b/apps/app_mixmonitor.c
@@ -292,7 +292,7 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
 
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	ast_pthread_create(&thread, &attr, mixmonitor_thread, mixmonitor);
+	ast_pthread_create_background(&thread, &attr, mixmonitor_thread, mixmonitor);
 	pthread_attr_destroy(&attr);
 
 }
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 0895476a72cc2e9a2e5d0c8362850d0a1ea82d32..f0dbe883eb11fff528039591a15fb05fb001aff3 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -596,7 +596,7 @@ static int statechange_queue(const char *dev, int state, void *ign)
 	strcpy(sc->dev, dev);
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	if (ast_pthread_create(&t, &attr, changethread, sc)) {
+	if (ast_pthread_create_background(&t, &attr, changethread, sc)) {
 		ast_log(LOG_WARNING, "Failed to create update thread!\n");
 		free(sc);
 	}
diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c
index 44dc22fc33f677379b9858b68daf19b95a9f0f81..343eb035bef52fa28759a4622c0ebd5012968e75 100644
--- a/channels/chan_alsa.c
+++ b/channels/chan_alsa.c
@@ -1151,7 +1151,7 @@ static int load_module(void)
 
 	ast_cli_register_multiple(cli_alsa, sizeof(cli_alsa) / sizeof(struct ast_cli_entry));
 
-	ast_pthread_create(&sthread, NULL, sound_thread, NULL);
+	ast_pthread_create_background(&sthread, NULL, sound_thread, NULL);
 #ifdef ALSA_MONITOR
 	if (alsa_monitor_start())
 		ast_log(LOG_ERROR, "Problem starting Monitoring\n");
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
index f5bad9c4351ca07e4e47f8de972a5f0c6c900ba8..6f45566172c25c6bb5ee2966778edebcb29f82c3 100644
--- a/channels/chan_h323.c
+++ b/channels/chan_h323.c
@@ -2590,7 +2590,7 @@ static int restart_monitor(void)
 		pthread_attr_init(&attr);
 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
 			monitor_thread = AST_PTHREADT_NULL;
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 99949ed9a7e73432651ca0716af9b49136a0c634..51589392b99acc3a74854c379125a3c4d603fb7f 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -6106,7 +6106,7 @@ static int iax_park(struct ast_channel *chan1, struct ast_channel *chan2)
 	if ((d = ast_calloc(1, sizeof(*d)))) {
 		d->chan1 = chan1m;
 		d->chan2 = chan2m;
-		if (!ast_pthread_create(&th, NULL, iax_park_thread, d))
+		if (!ast_pthread_create_background(&th, NULL, iax_park_thread, d))
 			return 0;
 		free(d);
 	}
@@ -8083,8 +8083,8 @@ static int start_network_thread(void)
 			AST_LIST_UNLOCK(&idle_list);
 		}
 	}
-	ast_pthread_create(&schedthreadid, NULL, sched_thread, NULL);
-	ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
+	ast_pthread_create_background(&schedthreadid, NULL, sched_thread, NULL);
+	ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
 	if (option_verbose > 1)
 		ast_verbose(VERBOSE_PREFIX_2 "%d helper threaads started\n", threadcount);
 	return 0;
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index cd2cad804bdbc92614dcdaf061f7bf8ee98841cc..ca37eee9d6e16a0ea97feb516f9637aa4a7ceab1 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -3500,7 +3500,7 @@ static int restart_monitor(void)
 		pthread_kill(monitor_thread, SIGURG);
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;
diff --git a/channels/chan_oss.c b/channels/chan_oss.c
index b791153124198c00e86926f70108c8cb79eb82f7..088a4e285cadcfb827069c183c2b7c2a7f075799 100644
--- a/channels/chan_oss.c
+++ b/channels/chan_oss.c
@@ -1540,7 +1540,7 @@ static struct chan_oss_pvt *store_config(struct ast_config *cfg, char *ctg)
 		ast_log(LOG_ERROR, "Unable to create pipe\n");
 		goto error;
 	}
-	ast_pthread_create(&o->sthread, NULL, sound_thread, o);
+	ast_pthread_create_background(&o->sthread, NULL, sound_thread, o);
 	/* link into list of devices */
 	if (o != &oss_default) {
 		o->next = oss_default.next;
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index a6e3d7b454be0f3738ea4152fdc6022d7c213a07..dbf44f9fc21dfdd1e2c92efa7c76bb258dcb7b6a 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -1157,7 +1157,7 @@ static int restart_monitor()
 	}
 	monitor = 1;
 	/* Start a new monitor */
-	if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+	if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 		ast_mutex_unlock(&monlock);
 		ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 		return -1;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 60c1e59968b1f6bea6c1fde2418269760a0011dc..e5e432ab16b373de35d471645f7f364c12b48d13 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -12275,7 +12275,7 @@ static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct
 		d->chan1 = transferee;	/* Transferee */
 		d->chan2 = transferer;	/* Transferer */
 		d->seqno = seqno;
-		if (ast_pthread_create(&th, NULL, sip_park_thread, d) < 0) {
+		if (ast_pthread_create_background(&th, NULL, sip_park_thread, d) < 0) {
 			/* Could not start thread */
 			free(d);	/* We don't need it anymore. If thread is created, d will be free'd
 					   by sip_park_thread() */
@@ -14619,7 +14619,7 @@ static int restart_monitor(void)
 		pthread_kill(monitor_thread, SIGURG);
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index 57fb071e8c0967ff6196b48e0d547374784e3da4..e6444cf27b867bbd7958a0f68d7670c7eb579697 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -4331,7 +4331,7 @@ static int restart_monitor(void)
 		pthread_kill(monitor_thread, SIGURG);
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;
@@ -4512,7 +4512,7 @@ static int reload_config(void)
 			if (option_verbose > 1)
 				ast_verbose(VERBOSE_PREFIX_2 "Skinny listening on %s:%d\n",
 					ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
-			ast_pthread_create(&accept_t,NULL, accept_thread, NULL);
+			ast_pthread_create_background(&accept_t,NULL, accept_thread, NULL);
 		}
 	}
 	ast_mutex_unlock(&netlock);
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index da1d48233e8d64bdea2f1ec06ac53e04e7382c4f..012a2f5519a235f7a88ae8e05a77fe8b783d2eb8 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -7245,7 +7245,7 @@ static int restart_monitor(void)
 #endif
 	} else {
 		/* Start a new monitor */
-		if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
+		if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
 			return -1;
@@ -9156,7 +9156,7 @@ static void *pri_dchannel(void *vpri)
 					idle = zt_request("Zap", AST_FORMAT_ULAW, idlen, &cause);
 					if (idle) {
 						pri->pvts[nextidle]->isidlecall = 1;
-						if (ast_pthread_create(&p, NULL, do_idle_thread, idle)) {
+						if (ast_pthread_create_background(&p, NULL, do_idle_thread, idle)) {
 							ast_log(LOG_WARNING, "Unable to start new thread for idle channel '%s'\n", idle->name);
 							zt_hangup(idle);
 						}
@@ -10192,7 +10192,7 @@ static int start_pri(struct zt_pri *pri)
 	/* Assume primary is the one we use */
 	pri->pri = pri->dchans[0];
 	pri->resetpos = -1;
-	if (ast_pthread_create(&pri->master, NULL, pri_dchannel, pri)) {
+	if (ast_pthread_create_background(&pri->master, NULL, pri_dchannel, pri)) {
 		for (i = 0; i < NUM_DCHANS; i++) {
 			if (!pri->dchannels[i])
 				break;
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 2fe5a87d3635b65343d310145cbd4aa59e1967ac..9ae2e4595a9337c2fbb08be2368a68ce462ac69c 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -246,15 +246,30 @@ static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct s
 		|| (sin1->sin_port != sin2->sin_port));
 }
 
-#define AST_STACKSIZE 256 * 1024
+#define AST_STACKSIZE 240 * 1024
+
+#if defined(LOW_MEMORY)
+#define AST_BACKGROUND_STACKSIZE 48 * 1024
+#else
+#define AST_BACKGROUND_STACKSIZE 240 * 1024
+#endif
 
 void ast_register_thread(char *name);
 void ast_unregister_thread(void *id);
 
-#define ast_pthread_create(a,b,c,d) ast_pthread_create_stack(a,b,c,d,0, \
-	 __FILE__, __FUNCTION__, __LINE__, #c)
-int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize,
-	const char *file, const char *caller, int line, const char *start_fn);
+int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *),
+			     void *data, size_t stacksize, const char *file, const char *caller,
+			     int line, const char *start_fn);
+
+#define ast_pthread_create(a, b, c, d) ast_pthread_create_stack(a, b, c, d,			\
+							        0,				\
+	 						        __FILE__, __FUNCTION__,		\
+ 							        __LINE__, #c)
+
+#define ast_pthread_create_background(a, b, c, d) ast_pthread_create_stack(a, b, c, d,			\
+									   AST_BACKGROUND_STACKSIZE,	\
+									   __FILE__, __FUNCTION__,	\
+									   __LINE__, #c)
 
 /*!
 	\brief Process a string to find and replace characters
diff --git a/main/asterisk.c b/main/asterisk.c
index 456370143c114e84e8aff83ef8f5d211ffebd29f..d80b3dea54a275d5ca4418de80dbff0c4f301067 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -300,7 +300,7 @@ void ast_register_thread(char *name)
 	if (!new)
 		return;
 	new->id = pthread_self();
-	new->name = name; /* this was a copy already */
+	new->name = name; /* steal the allocated memory for the thread name */
 	AST_LIST_LOCK(&thread_list);
 	AST_LIST_INSERT_HEAD(&thread_list, new, list);
 	AST_LIST_UNLOCK(&thread_list);
@@ -312,7 +312,7 @@ void ast_unregister_thread(void *id)
 
 	AST_LIST_LOCK(&thread_list);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
-		if ((void *)x->id == id) {
+		if ((void *) x->id == id) {
 			AST_LIST_REMOVE_CURRENT(&thread_list, list);
 			break;
 		}
@@ -859,7 +859,7 @@ static void *listener(void *unused)
 					fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK);
 					consoles[x].fd = s;
 					consoles[x].mute = ast_opt_mute;
-					if (ast_pthread_create(&consoles[x].t, &attr, netconsole, &consoles[x])) {
+					if (ast_pthread_create_background(&consoles[x].t, &attr, netconsole, &consoles[x])) {
 						ast_log(LOG_ERROR, "Unable to spawn thread to handle connection: %s\n", strerror(errno));
 						close(consoles[x].p[0]);
 						close(consoles[x].p[1]);
@@ -917,7 +917,7 @@ static int ast_makesocket(void)
 		return -1;
 	}
 	ast_register_verbose(network_verboser);
-	ast_pthread_create(&lthread, NULL, listener, NULL);
+	ast_pthread_create_background(&lthread, NULL, listener, NULL);
 
 	if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) {
 		struct passwd *pw;
diff --git a/main/autoservice.c b/main/autoservice.c
index 51a1e1ca676b60d6b517d92f55f4cc447b8a412d..1d9670794dab29e2d57729972e0153b0ed4f628e 100644
--- a/main/autoservice.c
+++ b/main/autoservice.c
@@ -111,7 +111,7 @@ int ast_autoservice_start(struct ast_channel *chan)
 		AST_LIST_INSERT_HEAD(&aslist, as, list);
 		res = 0;
 		if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
-			if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
+			if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
 				ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
 				/* There will only be a single member in the list at this point,
 				   the one we just added. */
diff --git a/main/cdr.c b/main/cdr.c
index 4d3ca86bffa88ba17fd5296bd1319ef466b52b36..fb243ff4931f5ce3352c8f28acac8ea1e0dcc9fa 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -853,7 +853,7 @@ void ast_cdr_submit_batch(int shutdown)
 	} else {
 		pthread_attr_init(&attr);
 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-		if (ast_pthread_create(&batch_post_thread, &attr, do_batch_backend_process, oldbatchitems)) {
+		if (ast_pthread_create_background(&batch_post_thread, &attr, do_batch_backend_process, oldbatchitems)) {
 			ast_log(LOG_WARNING, "CDR processing thread could not detach, now trying in this thread\n");
 			do_batch_backend_process(oldbatchitems);
 		} else {
@@ -1101,7 +1101,7 @@ static int do_reload(void)
 	   if it does not exist */
 	if (enabled && batchmode && (!was_enabled || !was_batchmode) && (cdr_thread == AST_PTHREADT_NULL)) {
 		ast_cond_init(&cdr_pending_cond, NULL);
-		if (ast_pthread_create(&cdr_thread, NULL, do_cdr, NULL) < 0) {
+		if (ast_pthread_create_background(&cdr_thread, NULL, do_cdr, NULL) < 0) {
 			ast_log(LOG_ERROR, "Unable to start CDR thread.\n");
 			ast_sched_del(sched, cdr_sched);
 		} else {
diff --git a/main/devicestate.c b/main/devicestate.c
index c434ce9a0a1a8bbc9b112c6ff6a04c8a8f7a0e25..3f38930d17061327aa8c005887919bf0ab9da5bd 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -374,7 +374,7 @@ static void *do_devstate_changes(void *data)
 int ast_device_state_engine_init(void)
 {
 	ast_cond_init(&change_pending, NULL);
-	if (ast_pthread_create(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
+	if (ast_pthread_create_background(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
 		ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
 		return -1;
 	}
diff --git a/main/dnsmgr.c b/main/dnsmgr.c
index 0cc0d63f8ef6c6afcdf5546037abb2858909968c..3f370e054c125bab940f607a5c4edda9b5d76175 100644
--- a/main/dnsmgr.c
+++ b/main/dnsmgr.c
@@ -390,7 +390,7 @@ static int do_reload(int loading)
 	/* if this reload enabled the manager, create the background thread
 	   if it does not exist */
 	if (enabled && !was_enabled && (refresh_thread == AST_PTHREADT_NULL)) {
-		if (ast_pthread_create(&refresh_thread, NULL, do_refresh, NULL) < 0) {
+		if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
 			ast_log(LOG_ERROR, "Unable to start refresh thread.\n");
 		}
 		else {
diff --git a/main/http.c b/main/http.c
index a1cd73a9134dcea7a83ef9afb0e4154a81e36e0b..0a78446968d8a091529e77f228b2869a3f158456 100644
--- a/main/http.c
+++ b/main/http.c
@@ -510,7 +510,7 @@ static void *http_root(void *data)
 				pthread_attr_init(&attr);
 				pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 				
-				if (ast_pthread_create(&launched, &attr, ast_httpd_helper_thread, ser)) {
+				if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
 					ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
 					fclose(ser->f);
 					free(ser);
@@ -589,7 +589,7 @@ static void http_server_start(struct sockaddr_in *sin)
 	}
 	flags = fcntl(httpfd, F_GETFL);
 	fcntl(httpfd, F_SETFL, flags | O_NONBLOCK);
-	if (ast_pthread_create(&master, NULL, http_root, NULL)) {
+	if (ast_pthread_create_background(&master, NULL, http_root, NULL)) {
 		ast_log(LOG_NOTICE, "Unable to launch http server on %s:%d: %s\n",
 				ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port),
 				strerror(errno));
diff --git a/main/manager.c b/main/manager.c
index 8e368bf0b4a25df44b33cfcfc971c8251f468a5f..2f3f1c5bbdcc4635fe0f159e57281bff59cf5d57 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2170,7 +2170,7 @@ static void *accept_thread(void *ignore)
 			s->eventq = s->eventq->next;
 		AST_LIST_UNLOCK(&sessions);
 		ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
-		if (ast_pthread_create(&s->t, &attr, session_do, s))
+		if (ast_pthread_create_background(&s->t, &attr, session_do, s))
 			destroy_session(s);
 	}
 	pthread_attr_destroy(&attr);
@@ -2785,7 +2785,7 @@ int init_manager(void)
 		fcntl(asock, F_SETFL, flags | O_NONBLOCK);
 		if (option_verbose)
 			ast_verbose("Asterisk Management interface listening on port %d\n", portno);
-		ast_pthread_create(&t, NULL, accept_thread, NULL);
+		ast_pthread_create_background(&t, NULL, accept_thread, NULL);
 	}
 	return 0;
 }
diff --git a/main/utils.c b/main/utils.c
index 22e5027a8fbbf11196eff5370d99f8ba26b2cdfc..3f44fe777fde7fb6ec5ff296080c2cf00722c9be 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -525,31 +525,38 @@ struct thr_arg {
  * are odd macros which start and end a block, so they _must_ be
  * used in pairs (the latter with a '1' argument to call the
  * handler on exit.
- * On BSD we don't need this, but we keep it for compatibility with the MAC.
+ * On BSD we don't need this, but we keep it for compatibility.
  */
 static void *dummy_start(void *data)
 {
 	void *ret;
-	struct thr_arg a = *((struct thr_arg *)data);	/* make a local copy */
+	struct thr_arg a = *((struct thr_arg *) data);	/* make a local copy */
 
+	/* note that even though data->name is a pointer to allocated memory,
+	   we are not freeing it here because ast_register_thread is going to
+	   keep a copy of the pointer and then ast_unregister_thread will
+	   free the memory
+	*/
 	free(data);
 	ast_register_thread(a.name);
-	pthread_cleanup_push(ast_unregister_thread, (void *)pthread_self());	/* on unregister */
+	pthread_cleanup_push(ast_unregister_thread, (void *) pthread_self());
 	ret = a.start_routine(a.data);
 	pthread_cleanup_pop(1);
+
 	return ret;
 }
 
-int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize,
-	const char *file, const char *caller, int line, const char *start_fn)
+int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *),
+			     void *data, size_t stacksize, const char *file, const char *caller,
+			     int line, const char *start_fn)
 {
 	struct thr_arg *a;
 
-	pthread_attr_t lattr;
 	if (!attr) {
-		pthread_attr_init(&lattr);
-		attr = &lattr;
+		attr = alloca(sizeof(*attr));
+		pthread_attr_init(attr);
 	}
+
 #ifdef __linux__
 	/* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED,
 	   which is kind of useless. Change this here to
@@ -558,27 +565,25 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*st
 	   This does mean that callers cannot set a different priority using
 	   PTHREAD_EXPLICIT_SCHED in the attr argument; instead they must set
 	   the priority afterwards with pthread_setschedparam(). */
-	errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED);
-	if (errno)
-		ast_log(LOG_WARNING, "pthread_attr_setinheritsched returned non-zero: %s\n", strerror(errno));
+	if ((errno = pthread_attr_setinheritsched(attr, PTHREAD_INHERIT_SCHED)))
+		ast_log(LOG_WARNING, "pthread_attr_setinheritsched: %s\n", strerror(errno));
 #endif
 
 	if (!stacksize)
 		stacksize = AST_STACKSIZE;
-	errno = pthread_attr_setstacksize(attr, stacksize);
-	if (errno)
-		ast_log(LOG_WARNING, "pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno));
-	a = ast_malloc(sizeof(*a));
-	if (!a)
-		ast_log(LOG_WARNING, "no memory, thread %s will not be listed\n", start_fn);
-	else {	/* remap parameters */
+
+	if ((errno = pthread_attr_setstacksize(attr, stacksize ? stacksize : AST_STACKSIZE)))
+		ast_log(LOG_WARNING, "pthread_attr_setstacksize: %s\n", strerror(errno));
+
+	if ((a = ast_malloc(sizeof(*a)))) {
 		a->start_routine = start_routine;
 		a->data = data;
 		start_routine = dummy_start;
 		asprintf(&a->name, "%-20s started at [%5d] %s %s()",
-			start_fn, line, file, caller);
+			 start_fn, line, file, caller);
 		data = a;
 	}
+
 	return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
 }
 
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index e1308306f0c1a3cda77574731aad0c553e7360a5..241cc5d4d167da6ad515c2ed56950077f1e95e84 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -2151,8 +2151,8 @@ static void *process_precache(void *ign)
 
 static int start_network_thread(void)
 {
-	ast_pthread_create(&netthreadid, NULL, network_thread, NULL);
-	ast_pthread_create(&precachethreadid, NULL, process_precache, NULL);
+	ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
+	ast_pthread_create_background(&precachethreadid, NULL, process_precache, NULL);
 	return 0;
 }
 
diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c
index c4714a09d559e80bd23810f9985e5a8356904609..ec008280bd6070b8de84eaa1b730c08d46508971 100644
--- a/pbx/pbx_spool.c
+++ b/pbx/pbx_spool.c
@@ -495,7 +495,7 @@ static int load_module(void)
 	snprintf(qdonedir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing_done");
 	pthread_attr_init(&attr);
  	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	if ((ret = ast_pthread_create(&thread,&attr,scan_thread, NULL)) != 0) {
+	if ((ret = ast_pthread_create_background(&thread,&attr,scan_thread, NULL)) != 0) {
 		ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
 		return -1;
 	}
diff --git a/res/res_jabber.c b/res/res_jabber.c
index e20fa9528b9ff99503d57a8fa6beea72565153ed..0e09b273e241fd6df5eeb4b2a7d6bd39513a5715 100644
--- a/res/res_jabber.c
+++ b/res/res_jabber.c
@@ -2368,7 +2368,7 @@ static int aji_reload()
 		ASTOBJ_RDLOCK(iterator);
 		if(iterator->state == AJI_DISCONNECTED) {
 			if (!iterator->thread)
-				ast_pthread_create(&iterator->thread, NULL, aji_recv_loop, iterator);
+				ast_pthread_create_background(&iterator->thread, NULL, aji_recv_loop, iterator);
 		} else if (iterator->state == AJI_CONNECTING)
 			aji_get_roster(iterator);
 		ASTOBJ_UNLOCK(iterator);
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 41f588c0e4d1630281d73a8958f9b6d5305a5ac4..a8b4d62e8002b8e841fcd5b1b82875f9b7b222ce 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -867,7 +867,7 @@ static int moh_register(struct mohclass *moh, int reload)
 #else
 		moh->pseudofd = -1;
 #endif
-		if (ast_pthread_create(&moh->thread, NULL, monmp3thread, moh)) {
+		if (ast_pthread_create_background(&moh->thread, NULL, monmp3thread, moh)) {
 			ast_log(LOG_WARNING, "Unable to create moh...\n");
 			if (moh->pseudofd > -1)
 				close(moh->pseudofd);
diff --git a/res/res_smdi.c b/res/res_smdi.c
index 87540e48fc45d5e7d267fda06af6362eeab7224f..c19b600e48a66734a787cd56768b6aced5652e5f 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -682,7 +682,7 @@ static int smdi_load(int reload)
                         /* start the listner thread */
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_3 "Starting SMDI monitor thread for %s\n", iface->name);
-			if (ast_pthread_create(&iface->thread, NULL, smdi_read, iface)) {
+			if (ast_pthread_create_background(&iface->thread, NULL, smdi_read, iface)) {
 				ast_log(LOG_ERROR, "Error starting SMDI monitor thread for %s\n", iface->name);
 				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
 				continue;
diff --git a/res/res_snmp.c b/res/res_snmp.c
index fbef97f0ab1f87be6bffd04ee88bcff1ad106bc1..2ccadc4073f0937c30ad210966fb85c07e73ae4e 100644
--- a/res/res_snmp.c
+++ b/res/res_snmp.c
@@ -96,7 +96,7 @@ static int load_module(void)
 
 	res_snmp_dont_stop = 1;
 	if (res_snmp_enabled)
-		return ast_pthread_create(&thread, NULL, agent_thread, NULL);
+		return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
 	else
 		return 0;
 }
@@ -121,7 +121,7 @@ static int reload(void)
 
 	res_snmp_dont_stop = 1;
 	if (res_snmp_enabled)
-		return ast_pthread_create(&thread, NULL, agent_thread, NULL);
+		return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
 	else
 		return 0;
 }