08-25-2010
A few problems with writing it in C.
1) You're assuming variables are atomic. Sometimes they're not.
2) You're assuming different threads have access to the same memory/cache. In multicore systems, this isn't always true, "memory barriers" are needed to force cores to be consistent with each other when necessary.
3) The compiler makes certain assumptions about memory. Unless you tell it otherwise, it will assume a variable is not "magic" and won't change mysteriously when its not looking (which is precisely what you're doing with threads). You have to make a variable volatile(i.e. "volatile int i") if you're going to have threads competing over it this way.
So, writing the algorithm in raw ANSI C isn't recommended. You might be able to make this work in raw C on a single-core system, maybe, if you make the shared variables volatile. I think there's also some extensions in GNU gcc for explicit atomic operations.
Last edited by Corona688; 08-25-2010 at 02:37 PM..
This User Gave Thanks to Corona688 For This Post:
10 More Discussions You Might Find Interesting
1. Programming
To anyone that can answer this:
Are the differences great between the ANSI and K&R standard? What are some of the major differences between them??
-REM (1 Reply)
Discussion started by: REM
1 Replies
2. Programming
Dear All,
I have to develope some C functions in Unix for a Magic program. The original MSE code which compiles the attached C program uses a +z option, but the cc compiler don't know this. The complete command in the compiler script is 'cc -c -Aa +z myfile.c'. The warning message is 'The -z... (4 Replies)
Discussion started by: Frankie
4 Replies
3. Programming
can somebody explain about the ANSI C vs POSIX. say i was using open and fopen, i know that open is POSIX, and fopen is ANSI C. i read that that POSIX is a system call and ANSI C is like a standard library function. wouldn't the fopen function has to call on open function anyway to open any kind... (2 Replies)
Discussion started by: bb00y
2 Replies
4. HP-UX
Hi! Can anyone help me with the problem i am having. Im new to hpux and i am trying to set up the programs i use. One such program is the irc client BitchX, ive ran it on several pc/sun boxes with no problems. On my c360 with an fx6 card and a eizo f56 17in monitor (1024x768 85hz vesa) the ansi... (0 Replies)
Discussion started by: Lewis
0 Replies
5. HP-UX
Good Day
I downloaded Server Evaluation copy of C/ANSI compiler, but when I try to compile a file with it, it gives me following error - (for HP-UX 11.11 v1 PA-RISC)
Internal Error: Codeword file /opt/ansic/newconfig/ansic.cwd missing or empty.
Detailed Errors are as follows
Internal... (3 Replies)
Discussion started by: shawnbishop
3 Replies
6. Programming
I am a student. And need help on following program. I want to make a c program.
I have to scan a sentence and I have to interchange a word from that sentence.
Example: Scan the sentence is " Drilling machine and Milling machine " . Replace the word "machine" by "operation". And output should... (2 Replies)
Discussion started by: dhaval chevli
2 Replies
7. Shell Programming and Scripting
Hi,
I am creating a file in Unix using a shell script. The file is getting created in the Unix - ANSI format. My requirement is to convert it to the PC - ANSI format. Can anyone tell me how to do this?
Thanks,
Sunil (0 Replies)
Discussion started by: ssmallya
0 Replies
8. HP-UX
I want to convert a file from Unix-ANSI to PC-ANSI format. How can i achieve that? (0 Replies)
Discussion started by: ssmallya
0 Replies
9. HP-UX
Hi,
How can i find which ansi c precompiler are installed on my hp-ux b11.23 itanuim machine ?
Thanks (3 Replies)
Discussion started by: yoavbe
3 Replies
10. Programming
I have very little experience with gcc compilation under different environments, so please bear with me. I carried over 20 years old project into Ubuntu 18.04, it has old style K&R parameters, no function declarations to speak of, many functions without return are not declared void, and on and... (8 Replies)
Discussion started by: migurus
8 Replies
LEARN ABOUT HPUX
crypt_unix
crypt_unix(5) Standards, Environments, and Macros crypt_unix(5)
NAME
crypt_unix - traditional UNIX crypt algorithm
DESCRIPTION
The crypt_unix algorithm is the traditional UNIX crypt algorithm. It is not considered sufficiently secure for current systems and is pro-
vided for backwards compatibility. The crypt_sunmd5(5), crypt_bsdmd5(5), or crypt_bsdbf(5) algorithm should be used instead.
The algorithm identifier for policy.conf(4) is __unix__. There is no entry in crypt.conf(4) for this algorithm.
The crypt_unix algorithm is internal to libc and provides the string encoding function used by crypt(3C) when the first character of the
salt is not a "$".
This algorithm is based on a one-way encryption algorithm with variations intended (among other things) to frustrate use of hardware imple-
mentations of a key search. Only the first eight characters of the key passed to crypt() are used with this algorithm; the rest are
silently ignored. The salt is a two-character string chosen from the set [a-zA-Z0-9./]. This string is used to perturb the hashing algo-
rithm in one of 4096 different ways.
The maximum password length for crypt_unix is 8 characters.
USAGE
The return value of the crypt_unix algorithm might not be portable among standard-conforming systems. See standards(5).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |Safe |
+-----------------------------+-----------------------------+
SEE ALSO
passwd(1), crypt(3C), crypt_genhash_impl(3C), crypt_gensalt(3C), crypt_gensalt_impl(3C), getpassphrase(3C), crypt.conf(4), passwd(4), pol-
icy.conf(4), attributes(5), crypt_bsdbf(5), crypt_bsdmd5(5), crypt_sunmd5(5), standards(5)
SunOS 5.10 6 Aug 2003 crypt_unix(5)