如何打印pthread_t(How to print pthread_t)
搜索,但不要碰到令人满意的答案。
我知道没有一种便携式打印pthread_t的方法。
你应该怎么做?
更新:
其实我不需要pthread_t,但是一些小的数字id,在debug消息中识别不同的线程。
在我的系统(64位RHEL 5.3)上,它被定义为unsigned long int,所以它是大数字,只是打印它在调试行中吃了宝贵的地方。 gdb如何分配短小时间
Searched, but don't come across a satisfying answer.
I know there's no a portable way to print a pthread_t.
How do you do it in your app?
Update:
Actually I don't need pthread_t, but some small numeric id, identifying in debug message different threads.
On my system (64 bit RHEL 5.3) it's defined as unsigned long int, so it's big number and just printing it eats a valuable place in debug line. How does gdb assign short tids?
原文:https://stackoverflow.com/questions/1759794
最满意答案
也许你做错了什么。 所以,这是使这项工作的步骤。
- 创建一个新项目:ASP.NET Core Web Application(.NET Core);
- 选择Web API模板;
- 运行项目并访问“api / values”以确保它正常工作;
- 将新项目添加到名为ClassLibrary的解决方案:类库(.NET Core);
- 删除Class1.cs并创建一个TestController.cs类;
在ClassLibrary项目的project.json中添加MVC依赖项:
"dependencies": { "NETStandard.Library": "1.6.0", "Microsoft.AspNetCore.Mvc": "1.0.0" },
将TestController.cs更新为:
[Route("api/[controller]")] public class TestController : Controller{ [HttpGet] public IEnumerable<string> Get() { return new string[] { "test1", "test2" }; } }
在WebAPI项目中添加对ClassLibrary的引用:右键单击“References” - >“Add Reference ...”或更新project.json,如下所示:
"dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "ClassLibrary": "1.0.0-*" },
更新您的Startup.cs
ConfigureServices
方法:public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddApplicationPart(Assembly.Load(new AssemblyName("ClassLibrary"))); }
- 再次运行项目并访问“api / test”;
Maybe you're doing something wrong. So, here are the steps to make this work.
- Create a new project: ASP.NET Core Web Application (.NET Core);
- Choose the Web API template;
- Run the project and access the "api/values" to make sure it's working;
- Add a new project to the solution named ClassLibrary: Class Library (.NET Core);
- Delete the Class1.cs and create a TestController.cs class;
Add the MVC dependency in the project.json from the ClassLibrary project:
"dependencies": { "NETStandard.Library": "1.6.0", "Microsoft.AspNetCore.Mvc": "1.0.0" },
Update your TestController.cs to be like this:
[Route("api/[controller]")] public class TestController : Controller{ [HttpGet] public IEnumerable<string> Get() { return new string[] { "test1", "test2" }; } }
Add the reference to ClassLibrary in your WebAPI Project: right-click on "References"->"Add Reference..." or update your project.json like this:
"dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "ClassLibrary": "1.0.0-*" },
Update your Startup.cs
ConfigureServices
method:public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddApplicationPart(Assembly.Load(new AssemblyName("ClassLibrary"))); }
- Run the project again and access "api/test";
相关问答
更多-
ASP.NET Core Middleware将参数传递给控制器(ASP.NET Core Middleware Passing Parameters to Controllers)[2022-08-06]
您可以使用HttpContext.Items传递管道内的任意值: context.Items["some"] = "value"; You can use HttpContext.Items to pass arbitrary values inside the pipeline: context.Items["some"] = "value"; -
从ASP.NET核心中的类库加载和注册API控制器(Loading and registering API Controllers From Class Library in ASP.NET core)[2023-01-18]
也许你做错了什么。 所以,这是使这项工作的步骤。 创建一个新项目:ASP.NET Core Web Application(.NET Core); 选择Web API模板; 运行项目并访问“api / values”以确保它正常工作; 将新项目添加到名为ClassLibrary的解决方案:类库(.NET Core); 删除Class1.cs并创建一个TestController.cs类; 在ClassLibrary项目的project.json中添加MVC依赖项: "dependencies": { " ... -
结构图和ASP.NET核心(Structuremap and ASP.NET core)[2023-04-17]
将“StructureMap”包重命名为“structuremap”,似乎与NuGet套管有些奇怪的问题。 干杯:) Rename the "StructureMap" package to "structuremap", seems like some weird issue with NuGet casing. Cheers :) -
ASP.NET MVC Core - 使用自定义类库替换控制器(ASP.NET MVC Core - replace controllers using custom class library)[2023-07-27]
我终于知道如何做到这一点。 可以使用Order=0的Route属性来实现 [Route("[controller]/[action]",Name ="Replacement", Order = 0)] public IActionResult About() { ViewData["Message"] = "This is About from Custom controller!!!!!!!!!!!!!!"; return View(); } I finally manage how ... -
您的错误消息与您发布的代码不符。 但是看起来你的程序中有两个[Http*(Name = "Get")]注释。 但是,路由名称必须是唯一的。 https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing#route-name 或者更确切地说,从错误消息看来,具有相同路由名称的两个操作必须具有完全相同的URL模板。 原因是路由名称主要用于反向路由(即生成一个动作的URL),如果名称不唯一,那么该URL是不明确的 - 除非具有该名称的所有 ...
-
policy.AddAuthenticationSchemes(scheme1, scheme2) 这意味着为了使策略身份验证成功, 两个指定的身份验证方案都必须成功。 您可能设置了两种身份验证方案,以便在JWT身份验证成功时,它会自动成功进行cookie身份验证(在这种情况下设置cookie,因此在进一步请求时不再需要JWT令牌,但cookie已足够)。 因此,当JWT身份验证成功时,cookie身份验证也会成功。 但是,反之亦然:如果您只使用cookie来建立身份验证,那么JWT令牌可能根本就不存在。 ...
-
不同的asp.net web api控制器的不同认证机制(Different authentication mechanisms for different asp.net web api controllers)[2023-11-11]
查看Web API v2中的新身份验证筛选器。 它们专门用于使用身份验证方法注释控制器或操作。 您可以将身份验证方法直接实现到控制器中 - 或者使用OWIN / Katana回调到身份验证中间件。 请参阅此处获取基本身份验证中间件: https : //github.com/thinktecture/Thinktecture.IdentityModel/tree/master/source/Thinktecture.IdentityModel.Owin/Basic%20Authentication I en ... -
如果您想要网页和游戏的单独控制器或操作,您可以将逻辑移动到控制器调用的类中。 这样会更好并遵循单一责任规则,而不是一个返回两种响应类型的操作 You could move the logic into a class to be called by the controller if you want separate controllers or actions for the Webpage and game. This would be better and follow the single res ...
-
您需要在fetch中设置凭证选项,这将执行以下操作: Request接口的凭证只读属性指示用户代理是否应在跨源请求的情况下从其他域发送cookie。 这类似于XHR的withCredentials标志,但有三个可用值(而不是两个) omit :永远不要发送cookie。 same-origin :如果URL与调用脚本位于同一源,则发送用户凭据(cookie,基本http auth等)。 这是默认值。 include :始终发送用户凭据(cookie,基本http身份验证等),即使是跨域呼叫也是如此。 资源 ...
-
说到IIS,.NET Framework维护一个用于为ASP.NET请求提供服务的线程池,但是如果请求是同步处理的,那么处理请求的线程在处理请求时很忙,而且该线程不能服务另一个请求,如果线程池有无限数量的线程可供使用,但它没有问题。 因此,当您需要执行I / O密集型和其他非CPU绑定请求时,您将通过利用异步操作获得好处,如果您使用4之前的MVC版本,则可以使用AsyncController类,如果您使用异步方法正在使用MVC4或更高版本... 使用异步方法的好处之一就是如果您的网站正在处理用户提交的文件。 ...