Skip to contentSkip to conversation

thread_mutex_lock/3-1: make sure install signal hanldler first

PATCH New Kang Kai 2 participants 3 messages Dec 16, 2011 – Dec 22, 2011

lore
Share & tools
lore

Kang Kai

author
#0 lore raw

PATCH v2 1/1 thread_mutex_lock/3-1: make sure install signal hanldler first

Hi All,

Version 2 use a semphore semsync2 to sync parent and child thread instead of make parent sleep 1 second.

Regards,
Kai

------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#1 lore raw

PATCH 1/1 pthread_mutex_lock/3-1: make sure install signal hanldler first

Import a new semphore semsync2 to sync thread parent and child thread 'th_work', so that signal handlers are installed before receive signal USR1 and USR2.

---
 .../interfaces/pthread_mutex_lock/3-1.c            |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_lock/3-1.c +12 -1
index 771851d..a735f73 100644
@@ -96,6 +96,7 @@ sem_t semsig2;
 unsigned long count_sig=0;
 #endif
 sem_t semsync;
+sem_t semsync2;
 
 typedef struct
 {
@@ -165,6 +166,9 @@ void * threaded(void * arg)
 	if ((ret = sigaction (SIGUSR2, &sa, NULL)))
 	{ UNRESOLVED(ret, "Unable to register signal handler2"); }
 
+	if ((sem_post(&semsync2)))
+	{ UNRESOLVED(errno, "could not post semsync2"); }
+
 	/* Initialize the different mutex */
 	pma[4]=NULL;
 
@@ -301,12 +305,19 @@ int main (int argc, char * argv[])
 	if ((sem_init(&semsync, 0, 0)))
 	{ UNRESOLVED(errno, "semsync init"); }
 
+	if ((sem_init(&semsync2, 0, 0)))
+	{ UNRESOLVED(errno, "semsync2 init"); }
+
 	#if VERBOSE >1
 	output("Starting the worker thread\n");
 	#endif
 	if ((ret = pthread_create(&th_work, NULL, threaded, NULL)))
 	{ UNRESOLVED(ret, "Worker thread creation failed"); }
 
+	do {
+		ret = sem_wait(&semsync2);
+	} while (ret && (errno ==  EINTR));
+
 	arg1.thr = &th_work;
 	arg2.thr = &th_work;
 	arg1.sig = SIGUSR1;
@@ -359,4 +370,4 @@ int main (int argc, char * argv[])
 	#endif
 	#endif
 	PASSED;
-}
\ No newline at end of file
+}
Signature · 13 lines
1.7.5.4


------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#2 lore raw

Re: [LTP] [PATCH] pthread_mutex_lock/3-1: make sure install signal hanldler first

Hi!

Quoted 3 lines

Import a new semphore semsync2 to sync thread parent and child thread 'th_work', so that signal handlers are installed before receive signal USR1 and USR2.

Commited, as this is better than the previous state.

However the testcase implementation is quite questionable. It's trying to hammer the loop with pthread_mutex_lock()/pthread_mutext_unlock() with signals and the probability of signal arriving at the right time is not really high.

Far better implementation would lock in the mutex for some time while the second thread would send the signals meanwhile.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list