Skip to content
Snippets Groups Projects
Commit b93e5032 authored by rswindell's avatar rswindell
Browse files

Check if sibling threads of sopen() problem (when using fcntl).

parent a4fd6cc2
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,10 @@ static void getkey(void);
static void sem_test_thread(void* arg);
static void sleep_test_thread(void* arg);
static void sopen_test_thread(void* arg);
static void sopen_child_thread(void* arg);
static void lock_test_thread(void* arg);
typedef struct {
sem_t parent_sem;
sem_t child_sem;
......@@ -52,6 +54,17 @@ int main()
printf("%-15s: %s\n","Compiler" ,compiler);
printf("%-15s: %d\n","Random Number",xp_random(1000));
for(i=0;i<3;i++) {
if(_beginthread(
sopen_child_thread /* entry point */
,0 /* stack size (0=auto) */
,(void*)i /* data */
)==(unsigned long)-1)
printf("_beginthread failed\n");
else
SLEEP(1);
}
/* Exclusive sopen test */
printf("\nsopen() test\n");
if((fd=sopen(LOCK_FNAME,O_RDWR|O_CREAT,SH_DENYRW))==-1) {
......@@ -278,3 +291,18 @@ static void sopen_test_thread(void* arg)
if(fd!=-1)
close(fd);
}
static void sopen_child_thread(void* arg)
{
int fd;
if((fd=sopen(LOCK_FNAME,O_RDWR,SH_DENYWR))!=-1) {
if(arg)
printf("!FAILURE: was able to reopen in child thread\n");
else {
SLEEP(5000);
close(fd);
}
} else if(arg==0)
perror(LOCK_FNAME);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment