Created
February 15, 2016 18:54
-
-
Save tbonfort/a961d792c05f158e2054 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
str="aaaaaaaaaaaaaaaaaa"; | |
while true; do | |
if [ "$str" = "aaaaaaaaaaaaaaaaaa" ]; then | |
str="bbbbbbbbbbbbbbbbbbbbb" | |
else | |
str="aaaaaaaaaaaaaaaaaa" | |
fi | |
echo "$str | |
$str | |
$str" > /dev/shm/test.tmp | |
mv /dev/shm/test.tmp /dev/shm/test | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <apr_file_io.h> | |
#include <apr_pools.h> | |
#include <apr_strings.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <apr_thread_proc.h> | |
#include <apr_thread_mutex.h> | |
static void _remove_lineends(char *str) { | |
if(str) { | |
size_t len = strlen(str); | |
while(len>0) { | |
if(str[len-1] == '\n' || str[len-1] == '\r') { | |
str[len-1] = '\0'; | |
len--; | |
} else { | |
break; | |
} | |
} | |
} | |
} | |
static void* APR_THREAD_FUNC work_thread(apr_thread_t *thread, void *data) { | |
apr_pool_t *pool; | |
apr_file_t *f; | |
apr_pool_create(&pool,NULL); | |
while(1) { | |
int rv; | |
char *line1=NULL,*line2=NULL,*line3=NULL; | |
char line[1024]; | |
rv = apr_file_open(&f, "/dev/shm/test", | |
APR_FOPEN_READ|APR_FOPEN_BUFFERED|APR_FOPEN_BINARY,APR_OS_DEFAULT, | |
pool); | |
if(rv != APR_SUCCESS) { | |
char errmsg[120]; | |
printf("failed to open file %s\n",apr_strerror(rv,errmsg,120)); | |
exit(1); | |
} | |
if( (rv = apr_file_gets(line,1024,f))== APR_SUCCESS) { | |
_remove_lineends(line); | |
line1 = apr_pstrdup(pool,line); | |
} | |
if( (rv = apr_file_gets(line,1024,f))== APR_SUCCESS) { | |
_remove_lineends(line); | |
line2 = apr_pstrdup(pool,line); | |
} | |
if( (rv = apr_file_gets(line,1024,f))== APR_SUCCESS) { | |
_remove_lineends(line); | |
line3 = apr_pstrdup(pool,line); | |
} | |
apr_file_close(f); | |
if(!line1||!line2||!line3) { | |
printf("one line was NULL\n"); | |
exit(1); | |
} | |
if(strcmp(line1,line2)||strcmp(line1,line3)) { | |
printf("one line does not match\n"); | |
exit(1); | |
} | |
apr_pool_clear(pool); | |
} | |
} | |
int main(int argc, char **argv) { | |
apr_thread_t **threads; | |
int nthreads=128,n; | |
apr_status_t rv; | |
apr_threadattr_t *thread_attrs; | |
apr_pool_t *pool; | |
apr_initialize(); | |
apr_pool_create(&pool,NULL); | |
apr_threadattr_create(&thread_attrs, pool); | |
threads = (apr_thread_t**)apr_pcalloc(pool, nthreads*sizeof(apr_thread_t*)); | |
for(n=0; n<nthreads; n++) { | |
apr_thread_create(&threads[n], thread_attrs, work_thread, NULL, pool); | |
} | |
for(n=0; n<nthreads; n++) { | |
apr_thread_join(&rv, threads[n]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment