锁定自由数组元素交换(Lock Free Array Element Swapping)
在多线程环境中,为了进行线程安全的数组元素交换,我们将执行同步锁定。
// a is char array. synchronized(a) { char tmp = a[1]; a[1] = a[0]; a[0] = tmp; }
在上面的情况下我们是否可以使用以下API,以便我们可以进行无锁数组元素交换? 如果有,怎么样?
In multi-thread environment, in order to have thread safe array element swapping, we will perform synchronized locking.
// a is char array. synchronized(a) { char tmp = a[1]; a[1] = a[0]; a[0] = tmp; }
Is it possible that we can make use of the following API in the above situation, so that we can have a lock free array element swapping? If yes, how?
原文:https://stackoverflow.com/questions/1231913
最满意答案
是的,这是正确的方式,您在NSLog上获得相同的结果,只需点击页面并显示源代码即可。 你的url index.php是纯文本而不是由服务器解释,这就是你没有“Hello,PHP!”的原因。 结果是。
请参阅php hello world tutorial: http : //www.utexas.edu/learn/php/example1.shtml
结果: http : //www.utexas.edu/learn/php/ex1.php
改变你的代码:
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.utexas.edu/learn/php/ex1.php"]; NSURL *url = [[NSURL alloc] initWithString:urlstr];
yes it's the right way, you have the same result on your NSLog as rigth click on your page and show source code. Your url index.php is in plain text and not interpreted by the server, is why you haven't "Hello, PHP!" as a result.
see php hello world tutorial : http://www.utexas.edu/learn/php/example1.shtml
the result: http://www.utexas.edu/learn/php/ex1.php
change your code :
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.utexas.edu/learn/php/ex1.php"]; NSURL *url = [[NSURL alloc] initWithString:urlstr];
相关问答
更多-
您需要NULL终止缓冲区。 使缓冲区大小为6个字符,并将其初始化为零。 现在只填充前5个位置,单独留下最后一个位置。 char buffer[6] = {0}; // <-- Zero initializes the array for(int x = 0; x < 5; x++){ buffer[x] = in.get(); cout << x << " " << buffer[x] << endl; } cout << buffer << endl; return buffer; 或 ...
-
我认为NSPredicate本身并没有办法。 您似乎要求的是排序结果。 您可以通过在从谓词中返回结果后对结果进行排序来完成此操作。 在这种情况下,由于排序顺序不仅仅是按字母顺序排列,因此您应该使用NSArray的-sortedArrayUsingComparator:方法。 像这样的东西(没有经过测试,键入了我的头顶)。 NSArray *sortedStrings = [filtered sortedArrayUsingComparator:^NSComparisonResult(id obj1, id ...
-
为了让您的输出成为数据的十六进制编码,请按照此处找到的方法进行操作。 我稍微修改它们作为扩展方法: public static string ToHexString(this byte[] bytes) { return bytes == null ? string.Empty : BitConverter.ToString(bytes).Replace("-", string.Empty); } public static byte[] FromHexSt ...
-
objective-c NSDateFormatter from string返回null(objective-c NSDateFormatter date from string returns null)[2021-04-19]
NSDateFormatter的格式不正确。 您需要匹配预期输入的格式: [dateFormatter setDateFormat:@"MMMM d, yyyy"]; The NSDateFormatter has the incorrect format. You need to match the format of the expected input: [dateFormatter setDateFormat:@"MMMM d, yyyy"]; -
Objective-C中的UILexicon(UILexicon in Objective-C)[2023-05-22]
我从来没有使用过这个功能,但是对于“UILexicon”的快速网络搜索让我着迷于Apple的文档; 阅读和下面的链接填写图片很快。 应用程序扩展程序设计指南快速解释了哪些词典适用于: 每个自定义键盘(独立于其RequestsOpenAccess键的值)都可以通过UILexicon类访问基本的自动UILexicon词典。 利用这个课程以及您自己设计的词汇,在用户输入文本时提供建议和自动更正。 单击UILexicon链接将我带到该类的参考文档,这说明它是Apple提供的术语对的只读列表。 它的每个条目都是一个U ... -
您从getIPAddresss()获得的地址是接口的地址,而不是多播组的地址。 这里是你的例子中如何使用地址,你能发现问题吗? // construct an IGMP join request structure mc_req.imr_multiaddr.s_addr = inet_addr(mc_addr_str); mc_req.imr_interface.s_addr = htonl(INADDR_ANY) 您将多播地址设置为包含接口地址的mc_addr_str中的地址。 这看起来不正确吗? ;) ...
-
那么在将它添加到urlString 之前 ,serverAdress中有什么。 看起来好像serverAdress包含'//server.dyndns.org/webservices/service1.asmx/getHourlySales2?tarih2=20.01.2011%2016:00&tarih1=19.01.2011%2016:00&salesType=Hepsi' So what's in serverAdress before you add it to urlString. Looks a ...
-
PHP页面在objective-C中返回垃圾而不是返回字符串(PHP page returns junk instead of return string in objective-C)[2023-09-30]
是的,这是正确的方式,您在NSLog上获得相同的结果,只需点击页面并显示源代码即可。 你的url index.php是纯文本而不是由服务器解释,这就是你没有“Hello,PHP!”的原因。 结果是。 请参阅php hello world tutorial: http : //www.utexas.edu/learn/php/example1.shtml 结果: http : //www.utexas.edu/learn/php/ex1.php 改变你的代码: NSString *urlstr = [[NSS ... -
正如sln所指出的那样(他解决了这个问题),你不能匹配C中的任何东西,因为你必须打开多线选项(使用m),并且你在regexpal中匹配,因为它是打开的。 关于你的正则表达式,它可以用^(Page\s*\d+\s*:?\s*)$ 。 问号意味着前面的字符不必在这里, \s匹配任何空格类型字符(空格,制表符等)。 关于您的选择问题,正则表达式中的括号是捕获变量的内容。 所以,如果你这样做(Page( \d+|\d+))你将有两个不同的变量。 你想要的是(Page(?: \d+|\d+)) ,因为(?: ) :) ...
-
Objective-C在NSURLSessionDataTask中返回一个字符串(Objective-C Return a String in NSURLSessionDataTask)[2023-04-09]
我找到了一种方法...之后返回字符串 [self.dataTask resume]; I found a way... return the string after [self.dataTask resume];