473,549 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Are the functions "time" and "scandir" thread-safe?

hi,
my multithread application, running under solaris box, is crashing
eventually.
I tried to spot and substitute functions not "thread safe", but I
guess my search wasn't good enough. I have put localtime_r and
asctime_r where I was using localtime and asctime. But I didn't find
any correspondent _r function to "time".Also , I found that "readdir"
is not thread safe. But what about "scandir"?
Thanks for any help
Nov 13 '05 #1
9 5999
rn***@yahoo.com (rn***@yahoo.co m) wrote in
news:9a******** *************** ***@posting.goo gle.com:
my multithread application, running under solaris box, is crashing
eventually.
I tried to spot and substitute functions not "thread safe",
But C doesn't support threading.
any correspondent _r function to "time".Also , I found that "readdir"
is not thread safe. But what about "scandir"?


I've never seen these functions in C, are you sure you don't need some
other newsgroup that would know about these functions?

--
- Mark ->
--
Nov 13 '05 #2
"Mark A. Odell" <no****@embedde dfw.com> wrote in message news:<Xn******* *************** **********@130. 133.1.4>...
rn***@yahoo.com (rn***@yahoo.co m) wrote in
news:9a******** *************** ***@posting.goo gle.com:
my multithread application, running under solaris box, is crashing
eventually.
I tried to spot and substitute functions not "thread safe",


But C doesn't support threading.


#include <pthread.h> and link with pthread lib (-lpthread)
Nov 13 '05 #3
rn***@yahoo.com (rn***@yahoo.co m) wrote in
news:9a******** *************** ***@posting.goo gle.com:
> my multithread application, running under solaris box, is crashing
> eventually.
> I tried to spot and substitute functions not "thread safe",


But C doesn't support threading.


#include <pthread.h> and link with pthread lib (-lpthread)


That's not an ISO C header though, is it? No, it is not.

--
- Mark ->
--
Nov 13 '05 #4
Though I am probably breaking many "laws" of this newsgroup, I'll answer his
question. Because ISO C doesn't enforce thread safety, your question will
boil
down to your version of the compiler. In most cases, the time function is
not
thread safe.

If you beleive that these functions are not thread safe, whatever thread
support
libraries you are using will have mechanisms to force thread safety on these
functions.
What you will need to do is the following:

1. Create a shared lock on every call to the function in question.
2. Call the function.
3. Immediately copy the data returned from function to another set (Do not
just create
pointer to it, or worse copy the returned pointer).
4. release the lock.

Better yet, create some functions to do the above. This "may" help you
figure out if the
function is thread safe or not. Though not the quickest answer, not the
fastest, nor the least time consuming,
it is however a better answer than being berated for asking a non ISO
question in a newsgroup
whose name is comp.lang.c. It would be nice if the name were changed to
reflect what it is:
comp.lang.c.ISO .||.flame. :)

Michael Steve

"Mark A. Odell" <no****@embedde dfw.com> wrote in message
news:Xn******** *************** *********@130.1 33.1.4...
rn***@yahoo.com (rn***@yahoo.co m) wrote in
news:9a******** *************** ***@posting.goo gle.com:
> my multithread application, running under solaris box, is crashing
> eventually.
> I tried to spot and substitute functions not "thread safe",

But C doesn't support threading.


#include <pthread.h> and link with pthread lib (-lpthread)


That's not an ISO C header though, is it? No, it is not.

--
- Mark ->
--

Nov 13 '05 #5
Michael Steve wrote:
Though I am probably breaking many "laws" of this newsgroup,


Not to mention a few that apply to all of Usenet. Such as "Don't
top-post!". Also, your formatting is all screwy. Are you inserting your
own newlines? Because if so, you are placing them poorly and and your
lines are wrapping anyway, leaving short 1 or 2 word lines.

Besides that, there are good reasons to observe the topicality rules.
Please avoid posting off-topic messages in the future.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #6
On Fri, 05 Dec 2003 00:49:26 GMT, "Michael Steve"
<ms****@columbu s.rr.com> wrote:
Though I am probably breaking many "laws" of this newsgroup, I'll answer his
question.


Why? Do you have a personal reason to dislike the other contributors
to this group? Direct the OP to a suitable newsgroup, where he will
surely get a better variety of answers, and where your own answer can
be read, verified, and commented on by people who might know more than
you.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #7
"Michael Steve" <ms****@columbu s.rr.com> wrote in
news:qC******** **********@fe3. columbus.rr.com on Thu 04 Dec 2003
05:49:26p:
Though I am probably breaking many "laws" of this newsgroup, I'll
answer his question.


Incorrectly, I might add.

Nov 13 '05 #8
Michael Steve wrote:
Though I am probably breaking many "laws" of this newsgroup, I'll answer his
question.


At one time, I hated comp.lang.c because so many were against off-topic
posts. Despite my disagreeing point-of-view, I continued to read the
messages from this group in hopes of making a better C programmer out of
me. After my C class was over for the semester, I wandered over to an
old Visual Basic newsgroup I once followed, looking to see if any of the
old crew was still around. What I saw shocked me. Messages about Word,
Excel, web development, ADO, etc., etc., etc., plagued the newsgroup. I
estimated for every one on-topic message, there were at least nine
others, which were not. In addition, the same questions were commonly
asked three or four times a day. The number of posts became
overwhelming for people to keep up with. As a result, bad advice was
common place and corrections were rarely made.

Despite the off-topicality and repetitive nature of the messages, no one
seemed to care. Posts were answered and people seemed happy. It was
then that I gained a high level of respect for the people of CLC.
Although seemingly cruel at times, comp.lang.c was by far, the most
professional and informative of all newsgroups I frequently visited.
Messages were clear and quick to the point. Off-topic messages were
redirected to newsgroups possibly containing members more educated in
the topic then anybody here. Furthermore, keeping the amount of noise
down to a low has by far improved my and many others ability to track
down important messages using Google. Above all, if bad or incomplete
advice was given, the people of this newsgroup could be trusted on for
making the necessary corrections.

Has comp.lang.c made a better C programmer out of me? I hope so. If
you absolutely must answer an off-topic message, at least send it in an
email. I personally prefer the redirection for reasons of verification.
I would really hate to see comp.lang.c turn into another newsgroup run
by a bunch of kids. Please don't ruin it for the rest of us by
responding to off-topic posts the way you did.

Sean

Nov 13 '05 #9
rn***@yahoo.com (rn***@yahoo.co m) wrote in message news:<9a******* *************** ****@posting.go ogle.com>...
"Mark A. Odell" <no****@embedde dfw.com> wrote in message news:<Xn******* *************** **********@130. 133.1.4>...
rn***@yahoo.com (rn***@yahoo.co m) wrote in
news:9a******** *************** ***@posting.goo gle.com:
my multithread application, running under solaris box, is crashing
eventually.
I tried to spot and substitute functions not "thread safe",


But C doesn't support threading.


#include <pthread.h> and link with pthread lib (-lpthread)


Mark was hinting to you that your message is off-topic for
comp.lang.c, since it talks about libraries and functionality
that are not part of C as such. A good rule of thumb (though
not invariably true) is that if you need to mention a particular
implementation for your question to make sense, then it's
off-topic.

Since you're asking about programming on Solaris, I suggest
comp.unix.progr ammer or comp.unix.solar is.
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2760
by: Jason Morehouse | last post by:
Hello, Just wondering if anyone is using the apache worker module with php? I've complied php5 with zend threadsafe support, and apache2 with the MPM worker module on a Linux box. Everything seems sweet. mysqli_thread_safe() reports true... anyone know if this configuration may include modules that aren't threadsafe? ...
11
8413
by: Jeff Schwab | last post by:
Is it OK for multiple threads to use the same PrintWriter concurrently?
0
1340
by: Stephanie Stowe | last post by:
Hi. I have been posting like a looney on an issue I am working on. I will reiterate the background since you all do not want to remember my issues! I have an ASP app (biggish). We are creating the first of many JSP apps. Until such time as we re-engineer our ASP apps for our new JSP / Java / Websphere environment, we need a session bridge. ...
9
3172
by: John | last post by:
If a value type is immutable, I guess it's threadsafe to read it? But not threadsafe to assign a new value to it (can any value type be truely immutable? Isn't assigning a totally new value to it, like doing an modification, when no references are involved? I don't know enough about CLR) At the moment the whole: lock(anobject) {
2
2910
by: David | last post by:
I have a static method in the dll that looks like this public static int myStaticFunction(int input){ } My question is, should I use a mutex inside the function to ensure that the function is threadsafe? This is used for ASP.NET. I am asking this question without knowing how IIS works as a multi-threaded application. Does each...
3
2166
by: Diffident | last post by:
Hello All, Following is a static method. Can you please tell me if this is threadsafe...why? If it is not threadsafe...why? Thank you. public static string GetCachedApplicationWideObject(string HashtableKey) { //Cache holds the hashtable
9
2158
by: Pohihihi | last post by:
What could be the possible reasons (technical/non technical) of not using lots of static functions or variables in a program keeping in mind that Framework by itself has tons of static functions and variables?
2
3444
by: Macca | last post by:
Hi, I need a data structure such as an Array/ArrayList/Generic List to hold multiple instances of a user derfined class. This array will be accessed across multiple threads. However I dont want to lock the array itself as this will cause poor performance due to the array being accessed frequently. If I make the User defined class...
5
5716
by: Spam Catcher | last post by:
Hi all, I'm accessing a synchronized Streamwriter from potentially several threads to do some logging. Is the Flush command threadsafe too? Should I single thread the Flush command or will the Synchronized streamwriter handle that for me? Thanks!
17
3242
by: fmassei | last post by:
Dear all, I'm trying to put some old code in a portable, cross-platform library and I'm facing a big problem: is there a standard, platform- independent way to write a reentrant function that allocate dynamic memory? In other words: is it safe to use malloc() or free() in a thread-safe function? Thank you, Francesco
0
7450
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.