4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/util.h>
31 #include <pulse/xmalloc.h>
32 #include <pulsecore/flist.h>
33 #include <pulsecore/thread.h>
34 #include <pulsecore/log.h>
35 #include <pulsecore/core-util.h>
37 #define THREADS_MAX 20
39 static pa_flist *flist;
42 static void spin(void) {
51 static void thread_func(void *data) {
59 /* Allocate some memory, if possible take it from the flist */
60 if (b && (text = pa_flist_pop(flist)))
61 pa_log("%s: popped '%s'", s, text);
63 text = pa_sprintf_malloc("Block %i, allocated by %s", n++, s);
64 pa_log("%s: allocated '%s'", s, text);
71 /* Give it back to the flist if possible */
72 if (pa_flist_push(flist, text) < 0) {
73 pa_log("%s: failed to push back '%s'", s, text);
76 pa_log("%s: pushed", s);
81 if (pa_flist_push(flist, s) < 0)
85 int main(int argc, char* argv[]) {
86 pa_thread *threads[THREADS_MAX];
89 flist = pa_flist_new(0);
91 for (i = 0; i < THREADS_MAX; i++) {
92 threads[i] = pa_thread_new(thread_func, pa_sprintf_malloc("Thread #%i", i+1));
99 for (i = 0; i < THREADS_MAX; i++)
100 pa_thread_free(threads[i]);
102 pa_flist_free(flist, pa_xfree);